Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 941
Rich_F Avatar asked Mar 23 '17 14:03

Rich_F


People also ask

How does Postgres store timestamp with timezone?

The timestamptz datatype is a time zone-aware date and time data type. PostgreSQL stores the timestamptz in UTC value. When you insert a value into a timestamptz column, PostgreSQL converts the timestamptz value into a UTC value and stores the UTC value in the table.

Does Postgres store dates as UTC?

PostgreSQL assumes your local time zone for any type containing only date or time. All timezone-aware dates and times are stored internally in UTC . They are converted to local time in the zone specified by the TimeZone configuration parameter before being displayed to the client.


1 Answers

I think you want this:

charlie timestamp without time zone NOT NULL
   DEFAULT (current_timestamp AT TIME ZONE 'UTC')
like image 62
Laurenz Albe Avatar answered Nov 07 '22 02:11

Laurenz Albe