How do I load a column of data in postgres? For example, if I have a table and I add a new column via alter table that is an integer, (Say, if the current table has 1000 rows of data) and I want to add 1000 values to the new column. What's the best approach to doing this? I've looked at the Copy command but it doesn't seem (at least from the documentation I've read) allow copies into single columns. i've tried doing an update like this:
update table foo set column bar = (10,20,30,40,50) but that complains about setting an integer to type 'record', and requiring a cast.
Do I need to write a postgres stored procedure to somehow iterate over each row and add the column from a data source?
Well, it's not so much that there is a specific relationship between the primary key and the value, in this case the primary key is just a serial value.
So, for example if the columns are:
id, item_name (varchar) amount_in_stock (integer), and I want to add an integer column (minimum_required_amount) using alter table, how do i then load values for this column into the table? There isn't a relationship per se between the key and the new column. I tried doing an update my_table set minimum_required_amount = (10, 20,30,20,10);
but postgres doesn't seem to like this. Basically, I just want to load this data in starting at the first row into the minimum_required_amount column.