diff options
| author | Tom Lane | 2025-01-16 19:11:19 +0000 |
|---|---|---|
| committer | Tom Lane | 2025-01-16 19:11:19 +0000 |
| commit | d7674c9fab09d5bab427ba3b9b7a20b169aba715 (patch) | |
| tree | 081f69dbaf1d06de875389d6b898fcb279c70982 /src/test | |
| parent | bc10219b9c8931ff4f872b3e799da2208101c574 (diff) | |
Seek zone abbreviations in the IANA data before timezone_abbreviations.
If a time zone abbreviation used in datetime input is defined in
the currently active timezone, use that definition in preference
to looking in the timezone_abbreviations list. That allows us to
correctly handle abbreviations that have different meanings in
different timezones. Also, it eliminates an inconsistency between
datetime input and datetime output: the non-ISO datestyles for
timestamptz have always printed abbreviations taken from the IANA
data, not from timezone_abbreviations. Before this fix, it was
possible to demonstrate cases where casting a timestamp to text
and back fails or changes the value significantly because of that
inconsistency.
While this change removes the ability to override the IANA data about
an abbreviation known in the current zone, it's not clear that there's
any real use-case for doing so. But it is clear that this makes life
a lot easier for dealing with abbreviations that have conflicts across
different time zones.
Also update the pg_timezone_abbrevs view to report abbreviations
that are recognized via the IANA data, and *not* report any
timezone_abbreviations entries that are thereby overridden.
Under the hood, there are now two SRFs, one that pulls the IANA
data and one that pulls timezone_abbreviations entries. They're
combined by logic in the view. This approach was useful for
debugging (since the functions can be called on their own).
While I don't intend to document the functions explicitly,
they might be useful to call directly.
Also improve DecodeTimezoneAbbrev's caching logic so that it can
cache zone abbreviations found in the IANA data. Without that,
this patch would have caused a noticeable degradation of the
runtime of timestamptz_in.
Per report from Aleksander Alekseev and additional investigation.
Discussion: https://postgr.es/m/CAJ7c6TOATjJqvhnYsui0=CO5XFMF4dvTGH+skzB--jNhqSQu5g@mail.gmail.com
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/horology.out | 6 | ||||
| -rw-r--r-- | src/test/regress/expected/rules.out | 17 | ||||
| -rw-r--r-- | src/test/regress/expected/sysviews.out | 8 | ||||
| -rw-r--r-- | src/test/regress/expected/timestamptz.out | 59 | ||||
| -rw-r--r-- | src/test/regress/sql/horology.sql | 1 | ||||
| -rw-r--r-- | src/test/regress/sql/sysviews.sql | 3 | ||||
| -rw-r--r-- | src/test/regress/sql/timestamptz.sql | 17 |
7 files changed, 107 insertions, 4 deletions
diff --git a/src/test/regress/expected/horology.out b/src/test/regress/expected/horology.out index cb28dfbaee7..b90bfcd794f 100644 --- a/src/test/regress/expected/horology.out +++ b/src/test/regress/expected/horology.out @@ -3332,6 +3332,12 @@ SELECT to_timestamp('2011-12-18 11:38 MSK', 'YYYY-MM-DD HH12:MI TZ'); -- dyntz Sat Dec 17 23:38:00 2011 PST (1 row) +SELECT to_timestamp('2011-12-18 00:00 LMT', 'YYYY-MM-DD HH24:MI TZ'); -- dyntz + to_timestamp +------------------------------ + Sat Dec 17 23:52:58 2011 PST +(1 row) + SELECT to_timestamp('2011-12-18 11:38ESTFOO24', 'YYYY-MM-DD HH12:MITZFOOSS'); to_timestamp ------------------------------ diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index ff921bbda00..856a8349c50 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -2629,10 +2629,19 @@ pg_tables| SELECT n.nspname AS schemaname, LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"])); -pg_timezone_abbrevs| SELECT abbrev, - utc_offset, - is_dst - FROM pg_timezone_abbrevs() pg_timezone_abbrevs(abbrev, utc_offset, is_dst); +pg_timezone_abbrevs| SELECT z.abbrev, + z.utc_offset, + z.is_dst + FROM pg_timezone_abbrevs_zone() z(abbrev, utc_offset, is_dst) +UNION ALL + SELECT a.abbrev, + a.utc_offset, + a.is_dst + FROM pg_timezone_abbrevs_abbrevs() a(abbrev, utc_offset, is_dst) + WHERE (NOT (EXISTS ( SELECT 1 + FROM pg_timezone_abbrevs_zone() z2(abbrev, utc_offset, is_dst) + WHERE (z2.abbrev = a.abbrev)))) + ORDER BY 1; pg_timezone_names| SELECT name, abbrev, utc_offset, diff --git a/src/test/regress/expected/sysviews.out b/src/test/regress/expected/sysviews.out index 91089ac215f..352abc0bd42 100644 --- a/src/test/regress/expected/sysviews.out +++ b/src/test/regress/expected/sysviews.out @@ -223,3 +223,11 @@ select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; t (1 row) +-- One specific case we can check without much fear of breakage +-- is the historical local-mean-time value used for America/Los_Angeles. +select * from pg_timezone_abbrevs where abbrev = 'LMT'; + abbrev | utc_offset | is_dst +--------+-------------------------------+-------- + LMT | @ 7 hours 52 mins 58 secs ago | f +(1 row) + diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out index a6dd45626ce..36349e363f2 100644 --- a/src/test/regress/expected/timestamptz.out +++ b/src/test/regress/expected/timestamptz.out @@ -176,6 +176,65 @@ SELECT '205000-01-10 17:32:01 Europe/Helsinki'::timestamptz; -- non-DST Fri Jan 10 07:32:01 205000 PST (1 row) +-- Recognize "LMT" as whatever it means in the current zone +SELECT 'Jan 01 00:00:00 1000 LMT'::timestamptz; + timestamptz +------------------------------ + Wed Jan 01 00:00:00 1000 LMT +(1 row) + +SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; + timestamptz +------------------------------ + Sun Dec 31 23:52:58 2023 PST +(1 row) + +SET timezone = 'Europe/London'; +SELECT 'Jan 01 00:00:00 1000 LMT'::timestamptz; + timestamptz +------------------------------ + Wed Jan 01 00:00:00 1000 LMT +(1 row) + +SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; + timestamptz +------------------------------ + Mon Jan 01 00:01:15 2024 GMT +(1 row) + +-- which might be nothing +SET timezone = 'UTC'; +SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; -- fail +ERROR: invalid input syntax for type timestamp with time zone: "Jan 01 00:00:00 2024 LMT" +LINE 1: SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; + ^ +-- Another example of an abbrev that varies across zones +SELECT '1912-01-01 00:00 MMT'::timestamptz; -- from timezone_abbreviations + timestamptz +------------------------------ + Sun Dec 31 17:30:00 1911 UTC +(1 row) + +SET timezone = 'America/Montevideo'; +SELECT '1912-01-01 00:00'::timestamptz; + timestamptz +------------------------------ + Mon Jan 01 00:00:00 1912 MMT +(1 row) + +SELECT '1912-01-01 00:00 MMT'::timestamptz; + timestamptz +------------------------------ + Mon Jan 01 00:00:00 1912 MMT +(1 row) + +SELECT '1912-01-01 00:00 MMT'::timestamptz AT TIME ZONE 'UTC'; + timezone +-------------------------- + Mon Jan 01 03:44:51 1912 +(1 row) + +RESET timezone; -- Test non-error-throwing API SELECT pg_input_is_valid('now', 'timestamptz'); pg_input_is_valid diff --git a/src/test/regress/sql/horology.sql b/src/test/regress/sql/horology.sql index 4aa88b4ba9a..1310b432773 100644 --- a/src/test/regress/sql/horology.sql +++ b/src/test/regress/sql/horology.sql @@ -538,6 +538,7 @@ SELECT to_timestamp('2011-12-18 11:38 EST', 'YYYY-MM-DD HH12:MI TZ'); SELECT to_timestamp('2011-12-18 11:38 -05', 'YYYY-MM-DD HH12:MI TZ'); SELECT to_timestamp('2011-12-18 11:38 +01:30', 'YYYY-MM-DD HH12:MI TZ'); SELECT to_timestamp('2011-12-18 11:38 MSK', 'YYYY-MM-DD HH12:MI TZ'); -- dyntz +SELECT to_timestamp('2011-12-18 00:00 LMT', 'YYYY-MM-DD HH24:MI TZ'); -- dyntz SELECT to_timestamp('2011-12-18 11:38ESTFOO24', 'YYYY-MM-DD HH12:MITZFOOSS'); SELECT to_timestamp('2011-12-18 11:38-05FOO24', 'YYYY-MM-DD HH12:MITZFOOSS'); SELECT to_timestamp('2011-12-18 11:38 JUNK', 'YYYY-MM-DD HH12:MI TZ'); -- error diff --git a/src/test/regress/sql/sysviews.sql b/src/test/regress/sql/sysviews.sql index b2a79237543..66179f026b3 100644 --- a/src/test/regress/sql/sysviews.sql +++ b/src/test/regress/sql/sysviews.sql @@ -98,3 +98,6 @@ set timezone_abbreviations = 'Australia'; select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; set timezone_abbreviations = 'India'; select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +-- One specific case we can check without much fear of breakage +-- is the historical local-mean-time value used for America/Los_Angeles. +select * from pg_timezone_abbrevs where abbrev = 'LMT'; diff --git a/src/test/regress/sql/timestamptz.sql b/src/test/regress/sql/timestamptz.sql index a92586c363e..2fa5378a572 100644 --- a/src/test/regress/sql/timestamptz.sql +++ b/src/test/regress/sql/timestamptz.sql @@ -109,6 +109,23 @@ SELECT '20500110 173201 Europe/Helsinki'::timestamptz; -- non-DST SELECT '205000-07-10 17:32:01 Europe/Helsinki'::timestamptz; -- DST SELECT '205000-01-10 17:32:01 Europe/Helsinki'::timestamptz; -- non-DST +-- Recognize "LMT" as whatever it means in the current zone +SELECT 'Jan 01 00:00:00 1000 LMT'::timestamptz; +SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; +SET timezone = 'Europe/London'; +SELECT 'Jan 01 00:00:00 1000 LMT'::timestamptz; +SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; +-- which might be nothing +SET timezone = 'UTC'; +SELECT 'Jan 01 00:00:00 2024 LMT'::timestamptz; -- fail +-- Another example of an abbrev that varies across zones +SELECT '1912-01-01 00:00 MMT'::timestamptz; -- from timezone_abbreviations +SET timezone = 'America/Montevideo'; +SELECT '1912-01-01 00:00'::timestamptz; +SELECT '1912-01-01 00:00 MMT'::timestamptz; +SELECT '1912-01-01 00:00 MMT'::timestamptz AT TIME ZONE 'UTC'; +RESET timezone; + -- Test non-error-throwing API SELECT pg_input_is_valid('now', 'timestamptz'); SELECT pg_input_is_valid('garbage', 'timestamptz'); |
