I need to set in a column in postgresql
the current date of the insertion as default value for the field.
How can I do this?
I need to set in a column in postgresql
the current date of the insertion as default value for the field.
How can I do this?
You can set the default value for column creation, for example:
my_date date not null default CURRENT_DATE
If your table already exists you need to update it
alter table minha_table
alter column minha_date set default current_timestamp
If you are creating it you can already create the column with the default value
create table minha_table
(
minha_date date not null default CURRENT_DATE
);
(CURRENT_DATE is basically a synonym for now() and a cast to date).