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.
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.
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.
I think you want this:
charlie timestamp without time zone NOT NULL
DEFAULT (current_timestamp AT TIME ZONE 'UTC')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With