Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALTER table column to timestamp now() properties

I created a table in postgres from samples I found on the internet. The definition of the column stored is:

stored  | timestamp without time zone | default '2014-04-11 21:19:20.144487'::timestamp without time zone

How do I alter this to be a "normal" timestamp now() type? So it will stamp the current date-time when inserting data?

Thank you all in advance!

like image 333
Shirker Avatar asked Oct 17 '25 17:10

Shirker


2 Answers

If you're trying to change the default value . . .

alter table your-table-name
alter column stored set default current_timestamp
like image 50
Mike Sherrill 'Cat Recall' Avatar answered Oct 19 '25 13:10

Mike Sherrill 'Cat Recall'


For changing the field type and default value the syntax will be ...

alter table your-table-name
alter column your-field type timestamp,
alter column your-field set default current_timestamp;
like image 42
Ciges Avatar answered Oct 19 '25 14:10

Ciges