I have several existing tables in which I need to modify various columns to have a default value.
How can I use the default value to the old records that are NULLso old records will comply with the new
ALTER TABLE "mytable" ALTER COLUMN "my_column" SET DEFAULT NOW();
After changing the table, it looks something like this:
Table "public.mytable"
Column | Type | Modifiers
id | integer | not null default nextval('mytable_id_seq'::regclass)
....
my_column | timestamp(0) with time zone | default now()
Indexes:
"mytable_pkey" PRIMARY KEY, btree (id)
Is there an easy way to have all columns that are currently null and also that have a default value for the default value?
source
share