Skip to content

Instantly share code, notes, and snippets.

@pragmasoft-ua
Created March 27, 2017 07:39
Show Gist options
  • Save pragmasoft-ua/59e311865fd104fcd0938df3a7631b24 to your computer and use it in GitHub Desktop.
Save pragmasoft-ua/59e311865fd104fcd0938df3a7631b24 to your computer and use it in GitHub Desktop.
create table timetest(a timestamp, b timestamp);
insert into timetest values(TIMESTAMP WITH TIME ZONE '2017-03-01 01:00:00+00', TIMESTAMP WITH TIME ZONE '2017-03-01 03:00:00+02');
select * from timetest where a = b;
a | b
---------------------+---------------------
2017-03-01 03:00:00 | 2017-03-01 03:00:00
(1 row)
select extract(timezone from a), a, extract(timezone from b), b from timetest where a = b;
ERROR: timestamp units "timezone" not supported
drop table timetest;
DROP TABLE
create table timetest(a timestamptz, b timestamptz);
insert into timetest values(TIMESTAMP WITH TIME ZONE '2017-03-01 01:00:00+00', TIMESTAMP WITH TIME ZONE '2017-03-01 03:00:00+02');
select extract(timezone_hour from a) tz_a, a, extract(timezone_hour from b) tz_b, b from timetest where a = b;
tz_a | a | tz_b | b
------+------------------------+------+------------------------
2 | 2017-03-01 03:00:00+02 | 2 | 2017-03-01 03:00:00+02
set timezone=utc;
SET
select extract(timezone_hour from a) tz_a, a, extract(timezone_hour from b) tz_b, b from timetest where a = b;
tz_a | a | tz_b | b
------+------------------------+------+------------------------
0 | 2017-03-01 01:00:00+00 | 0 | 2017-03-01 01:00:00+00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment