Search code examples
postgresqltimestampcreate-table

Postgresql Create Table Fieldname Timestamp with Time Zone UTC


What is the syntax for creating a table with a field with the UTC time zone?

I have for the fields:

(id INT PRIMARY KEY NOT NULL, 
 bravo timestamp without time zone DEFAULT now(),
 charlie timestamp with time zone UTC DEFAULT now()
)

This last field named charlie is not taking for some reason. I was hoping it was easy as just telling it had a time zone, then shoving UTC in there, and having the db figure out now() during input.


Solution

  • I think you want this:

    charlie timestamp without time zone NOT NULL
       DEFAULT (current_timestamp AT TIME ZONE 'UTC')