The SET TIME ZONE statement sets the default time zone for the current session.

In some cases, client drivers can drop and restart the connection to the server. When this happens, any session configurations made with SET statements are lost. It's therefore more reliable to set the time zone as an explicit part of a TIMESTAMP or TIMESTAMPTZ value.

Synopsis

SET TIME ZONE zone_value

Required Privileges

No privileges are required to set the default time zone.

Parameters

Parameter Description
zone_value The time zone for the current session.

This value can be a string representation of a local system-defined time zone (e.g., 'EST', 'America/New_York') or a positive or negative numeric offset from UTC (e.g., -7, +7). Also, DEFAULT, LOCAL, or 0 sets the session time zone to UTC.

Examples

> CREATE TABLE timestamps (a INT PRIMARY KEY, b TIMESTAMPTZ);
> INSERT INTO timestamps VALUES (1, TIMESTAMPTZ '2016-03-26 10:10:10-05:00');
> SELECT * FROM timestamps;
+---+---------------------------+
| a |             b             |
+---+---------------------------+
| 1 | 2016-03-26 15:10:10+00:00 |
+---+---------------------------+
# Note that the timestamp returned is UTC-05:00, which is the equivalent of EST.

Set the default time zone via SET TIME ZONE

> SET TIME ZONE 'EST';
> SHOW TIME ZONE;
+-----------+
| TIME ZONE |
+-----------+
| EST       |
+-----------+
(1 row)
> SET TIME ZONE DEFAULT;
> SHOW TIME ZONE;
+-----------+
| TIME ZONE |
+-----------+
| UTC       |
+-----------+
(1 row)

See Also



Yes No