Question:
Is there a postgres query to add a new column to an existing table and to automatically populate that column for all rows of the table with a certain value, let's say "A1", just once, as the column is created, so that I can still set the DEFAULT value of the column to another value, let's say "B2"?
Just to be clear, I am looking for something like this:
Given my_table:
name | work
------------------------
bob | fireman
carl | teacher
alice | policeman
my query
ALTER TABLE my_table
ADD COLUMN description varchar(100)
DEFAULT "B2"
COMMAND_I_D_WISH_TO_KNOW "A1";
changes my_table into
name | work | description
-------------------------------------
bob | fireman | "A1"
carl | teacher | "A1"
alice | policeman | "A1"
so that if afterwards I run the query
INSERT INTO my_table(name, work)
VALUES karen, developer;
my_tables becomes
name | work | description
-------------------------------------
bob | fireman | "A1"
carl | teacher | "A1"
alice | policeman | "A1"
karen | developer | "B2"