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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix some odd behaviors when using a SQL-style simple GMT offset
Date: 2013-11-01 16:14:17
Message-ID: E1VcHMX-0007Ls-9z@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2013-11-01 16:51:34 pgsql: Remove internal uses of CTimeZone/HasCTZSet.
Previous Message Robert Haas 2013-10-31 15:10:04 pgsql: Use appendStringInfoString instead of appendStringInfo where pos