Reputation: 8856
Let's start with a test table:
CREATE TABLE test
(
ts_tz timestamp with time zone
);
Let's insert one row of data:
INSERT INTO
test (ts_tz)
VALUES
(TIMESTAMP WITH TIME ZONE '2016-08-12 10:22:31.949271-00')
;
Now, let's query this one row:
postgres=# select * from test;
ts_tz
-------------------------------
2016-08-12 03:22:31.949271-07
Ok, this makes sense to me so far. ts_tz
is a timestamp with time zone and it's displaying as 03:22 with an offset of -07 because that's what my time zone is.
Now, suppose I want to change the time zone to 'US/Pacific'.
postgres=# select ts_tz AT TIME ZONE 'US/Pacific' from test;
timezone
----------------------------
2016-08-12 03:22:31.949271
But now this returns a TIMESTAMP WITHOUT TIME ZONE.
Why is this? How do I keep it as a TIMESTAMP WITH TIME ZONE?
Upvotes: 0
Views: 193
Reputation: 51649
This is how AT TIME ZONE
construct works - timestamptz becomes timestamp without timezone
and vice versa:
https://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT
If you want timestamp with zone
at some time zone specified use SET
, eg:
t=# set timezone to 'EST';
SET
t=# select * from test;
ts_tz
-------------------------------
2016-08-12 05:22:31.949271-05
(1 row)
Upvotes: 1