EAT(East Africa Time) is three hours ahead of UTC (UTC+03:00).
It's represented as UTC+03:00
in ISO-8601 format.
But AT TIME ZONE
only supports timezones represented in POSIX-style.
In POSIX-style, the positive sign is used for zones west of Greenwich. (Note that this is the opposite of the ISO-8601 sign convention used elsewhere in PostgreSQL.)
Format |
PST |
ART |
W←UTC→E |
EAT |
HKT |
ISO-8601 |
UTC-08 |
UTC-03 |
UTC+00 |
UTC+03 |
UTC+08 |
POSIX-style |
UTC+08 |
UTC+03 |
UTC+00 |
UTC-03 |
UTC-08 |
In POSIX-style, the correct representation of EAT can be:
The result of the following SQL statement must be TRUE
.
select now() at time zone -3 = now() at time zone 'EAT';
Confusingly, set time zone
statement supports ISO-8601, not POSIX-style.
Execute the following SQL statements in sequence to find the difference.
# |
SQL |
Result |
① |
set time zone -3; |
SET |
② |
select now(); |
2022-02-24 04:53:41.921391-03 |
③ |
select timestamp '2022-02-24 12:00' at time zone -3; |
2022-02-24 06:00:00-03 |
④ |
select timestamp '2022-02-24 12:00' at time zone +3; |
2022-02-24 12:00:00-03 |
⑤ |
set time zone 3; |
SET |
⑥ |
select now(); |
2022-02-24 10:54:10.283953+03 |
⑦ |
select timestamp '2022-02-24 12:00' at time zone -3; |
2022-02-24 12:00:00+03 |
⑧ |
select timestamp '2022-02-24 12:00' at time zone +3; |
2022-02-24 18:00:00+03 |
⑨ |
set time zone local; |
SET |
⑩ |
select now(); |
2022-02-24 15:54:51.79643+08 |
⑪ |
select now() at time zone -3; |
2022-02-24 10:55:02.209886 |
⑫ |
select now() at time zone 3; |
2022-02-24 04:55:09.498461 |
⚠️Please be careful about this.
References: