I have a trigger on a PostgreSQL table that updates a timestamp field, but I want to get it in the right timezone. How can I set my column to always be in \'PST\' by default? H
How can I set my column to always be in 'PST' by default?
This is not possible / a misunderstanding. A timestamp column is not in any time zone. The time zone is never saved, not even for timestamp with time zone
(timestamptz
), which always saves UTC time. That name is a tad bit misleading, I'll give you that.
You have two very simple options:
now()
to a timestamptz
column.now()
to a timestamp
column. (The time zone offset is truncated in the cast.)If you want timestamps to be displayed for the 'PST' time zone, set the time zone setting of your session to that time zone (if it is not set already). For instance:
SET timezone='America/Anchorage'
Ample details in this related answer:
To find your time zone name:
If you want to save the original time zone of input values: