pgsql: Fix some odd behaviors when using a SQL-style simple GMT offset - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix some odd behaviors when using a SQL-style simple GMT offset
Date
Msg-id E1VcHMX-0007Ls-9z@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix some odd behaviors when using a SQL-style simple GMT offset timezone.

Formerly, when using a SQL-spec timezone setting with a fixed GMT offset
(called a "brute force" timezone in the code), the session_timezone
variable was not updated to match the nominal timezone; rather, all code
was expected to ignore session_timezone if HasCTZSet was true.  This is
of course obviously fragile, though a search of the code finds only
timeofday() failing to honor the rule.  A bigger problem was that
DetermineTimeZoneOffset() supposed that if its pg_tz parameter was
pointer-equal to session_timezone, then HasCTZSet should override the
parameter.  This would cause datetime input containing an explicit zone
name to be treated as referencing the brute-force zone instead, if the
zone name happened to match the session timezone that had prevailed
before installing the brute-force zone setting (as reported in bug #8572).
The same malady could affect AT TIME ZONE operators.

To fix, set up session_timezone so that it matches the brute-force zone
specification, which we can do using the POSIX timezone definition syntax
"<abbrev>offset", and get rid of the bogus lookaside check in
DetermineTimeZoneOffset().  Aside from fixing the erroneous behavior in
datetime parsing and AT TIME ZONE, this will cause the timeofday() function
to print its result in the user-requested time zone rather than some
previously-set zone.  It might also affect results in third-party
extensions, if there are any that make use of session_timezone without
considering HasCTZSet, but in all cases the new behavior should be saner
than before.

Back-patch to all supported branches.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/2e2134954ad1bf46f4ce9ffd0ddfaf369c66e10e

Modified Files
--------------
src/backend/commands/variable.c        |    2 ++
src/backend/utils/adt/datetime.c       |    6 -----
src/include/pgtime.h                   |    1 +
src/test/regress/expected/horology.out |   30 ++++++++++++++++++++++++
src/test/regress/sql/horology.sql      |   16 +++++++++++++
src/timezone/pgtz.c                    |   40 ++++++++++++++++++++++++++++++++
6 files changed, 89 insertions(+), 6 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix some odd behaviors when using a SQL-style simple GMT offset
Next
From: Tom Lane
Date:
Subject: pgsql: Remove internal uses of CTimeZone/HasCTZSet.