Postgresql Create Table Fieldname Timestamp with Time Zone UTC

Rich_F picture Rich_F · Mar 23, 2017 · Viewed 20.8k times · Source

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.

Answer

Laurenz Albe picture Laurenz Albe · Mar 23, 2017

I think you want this:

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