How to insert current date in postgresql?

4

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?

    
asked by anonymous 27.09.2016 / 21:13

2 answers

4

You can set the default value for column creation, for example:

my_date date not null default CURRENT_DATE

    
28.09.2016 / 11:20
1

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).
    
28.09.2016 / 15:25