I have a unix timestamp in seconds and want to convert it to a timestamp with timezone in postgres.
My confusion originates from the fact that the following does not add but removes the time zone:
SELECT to_timestamp(1632610656) at time zone 'Europe/Berlin'
=> "2021-09-26 00:57:36"
If I understand it correctly to_timestamp
creates a timestamp with time zone and given this the at time zone 'Europe/Berlin
would then remove the time zone? (this feels so strange to me?!).
If I now want to get the timestamp with time zone in Europe/Berlin
, is it correct that I need to do the following?
1. Option
SELECT to_timestamp(1632610656) at time zone 'UTC' at time zone 'Europe/Berlin'
=> "2021-09-25 20:57:36+00"
and NOT
2. Option
SELECT to_timestamp(1632610656) at time zone 'Europe/Berlin' at time zone 'Europe/Berlin'
=> "2021-09-25 22:57:36+00"
They obviously have different results. The first one is the correct one, right?
SELECT to_timestamp(1632610656) at time zone 'Europe/Berlin'
shows you what the time was in Berlin when there was 1632610656 in the server time zone.