pgsql: Seek zone abbreviations in the IANA data before timezone_abbrevi

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Seek zone abbreviations in the IANA data before timezone_abbrevi
Date: 2025-01-16 19:11:49
Message-ID: E1tYVHR-001xWD-Dw@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d7674c9fab09d5bab427ba3b9b7a20b169aba715

Modified Files
--------------
doc/src/sgml/config.sgml | 6 +-
doc/src/sgml/datatype.sgml | 4 +
doc/src/sgml/datetime.sgml | 42 +++++-
doc/src/sgml/system-views.sgml | 4 +-
src/backend/catalog/system_views.sql | 7 +-
src/backend/commands/variable.c | 2 +
src/backend/utils/adt/datetime.c | 242 +++++++++++++++++++++++++++---
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 12 +-
src/include/pgtime.h | 7 +
src/include/utils/datetime.h | 2 +
src/test/regress/expected/horology.out | 6 +
src/test/regress/expected/rules.out | 17 ++-
src/test/regress/expected/sysviews.out | 8 +
src/test/regress/expected/timestamptz.out | 59 ++++++++
src/test/regress/sql/horology.sql | 1 +
src/test/regress/sql/sysviews.sql | 3 +
src/test/regress/sql/timestamptz.sql | 17 +++
src/timezone/localtime.c | 114 ++++++++++++++
src/tools/pgindent/typedefs.list | 1 +
20 files changed, 521 insertions(+), 35 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2025-01-16 21:58:12 pgsql: Avoid calling pqsignal() with invalid signals on Windows fronten
Previous Message Tom Lane 2025-01-16 17:43:13 pgsql: Make pg_interpret_timezone_abbrev() check sp->defaulttype too.