]> granicus.if.org Git - postgresql/commit
Fix some odd behaviors when using a SQL-style simple GMT offset timezone.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Nov 2013 16:13:26 +0000 (12:13 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Nov 2013 16:13:26 +0000 (12:13 -0400)
commit2e2134954ad1bf46f4ce9ffd0ddfaf369c66e10e
tree5f127dcda6734a5e36d1301129a615a8eb086c6c
parenta37f94ae4106634babe53a30a0cfc80380c12431
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.
src/backend/commands/variable.c
src/backend/utils/adt/datetime.c
src/include/pgtime.h
src/test/regress/expected/horology.out
src/test/regress/sql/horology.sql
src/timezone/pgtz.c