RefLib

Reference library for AI

Back

postgresql_16:3.5.5.3 Time Zones

PostgreSQL 16 > The SQL Language > Data Types > Date/Time Types > Time Zones

Time zones, and time-zone conventions, are influenced by political decisions, not just earth geometry. Time zones around the world became somewhat standardized during the 1900s, but continue to be prone to arbitrary changes, particularly with respect to daylight-savings rules. PostgreSQL uses the widely-used IANA (Olson) time zone database for information about historical time zone rules. For times in the future, the assumption is that the latest known rules for a given time zone will continue to be observed indefinitely far into the future.

PostgreSQL endeavors to be compatible with the SQL standard definitions for typical usage. However, the SQL standard has an odd mix of date and time types and capabilities. Two obvious problems are: Although the date type cannot have an associated time zone, the time type can. Time zones in the real world have little meaning unless associated with a date as well as a time, since the offset can vary through the year with daylight-saving time boundaries. The default time zone is specified as a constant numeric offset from UTC. It is therefore impossible to adapt to daylight-saving time when doing date/time arithmetic across DST boundaries.

To address these difficulties, we recommend using date/time types that contain both date and time when using time zones. We do *not* recommend using the type time with time zone (though it is supported by PostgreSQL for legacy applications and for compliance with the SQL standard). PostgreSQL assumes your local time zone for any type containing only date or time.

All timezone-aware dates and times are stored internally in UTC. They are converted to local time in the zone specified by the (see guc-timezone) configuration parameter before being displayed to the client.

PostgreSQL allows you to specify time zones in three different forms: A full time zone name, for example America/New_York. The recognized time zone names are listed in the pg_timezone_names view (see (see postgresql_16:8.3.32)). PostgreSQL uses the widely-used IANA time zone data for this purpose, so the same time zone names are also recognized by other software. A time zone abbreviation, for example PST. Such a specification merely defines a particular offset from UTC, in contrast to full time zone names which can imply a set of daylight savings transition rules as well. The recognized abbreviations are listed in the pg_timezone_abbrevs view (see (see postgresql_16:8.3.31)). You cannot set the configuration parameters (see guc-timezone) or (see guc-log-timezone) to a time zone abbreviation, but you can use abbreviations in date/time input values and with the AT TIME ZONE operator. In addition to the timezone names and abbreviations, PostgreSQL will accept POSIX-style time zone specifications, as described in (see postgresql_16:9.2.5). This option is not normally preferable to using a named time zone, but it may be necessary if no suitable IANA time zone entry is available. In short, this is the difference between abbreviations and full names: abbreviations represent a specific offset from UTC, whereas many of the full names imply a local daylight-savings time rule, and so have two possible UTC offsets. As an example, 2014-06-04 12:00 America/New_York represents noon local time in New York, which for this particular date was Eastern Daylight Time (UTC-4). So 2014-06-04 12:00 EDT specifies that same time instant. But 2014-06-04 12:00 EST specifies noon Eastern Standard Time (UTC-5), regardless of whether daylight savings was nominally in effect on that date.

To complicate matters, some jurisdictions have used the same timezone abbreviation to mean different UTC offsets at different times; for example, in Moscow MSK has meant UTC+3 in some years and UTC+4 in others. PostgreSQL interprets such abbreviations according to whatever they meant (or had most recently meant) on the specified date; but, as with the EST example above, this is not necessarily the same as local civil time on that date.

In all cases, timezone names and abbreviations are recognized case-insensitively. (This is a change from PostgreSQL versions prior to 8.2, which were case-sensitive in some contexts but not others.)

Neither timezone names nor abbreviations are hard-wired into the server; they are obtained from configuration files stored under .../share/timezone/ and .../share/timezonesets/ of the installation directory (see (see postgresql_16:9.2.4)).

The (see guc-timezone) configuration parameter can be set in the file postgresql.conf, or in any of the other standard ways described in (see postgresql_16:4.5). There are also some special ways to set it: The SQL command SET TIME ZONE sets the time zone for the session. This is an alternative spelling of SET TIMEZONE TO with a more SQL-spec-compatible syntax. The PGTZ environment variable is used by libpq clients to send a SET TIME ZONE command to the server upon connection.

Back