No-rewrite timestamp<->timestamptz conversions
Noah Misch <noah@leadboat.com>
From: Noah Misch <noah@leadboat.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: Andres Freund <andres@2ndquadrant.com>, pgsql-hackers@postgresql.org
Date: 2015-02-06T01:36:18Z
Lists: pgsql-hackers
Attachments
- at-timezone-v1.patch (text/plain) patch v1
On Tue, Nov 05, 2013 at 05:02:58PM -0800, Josh Berkus wrote: > I'd also love some way of doing a no-rewrite conversion between > timestamp and timestamptz, based on the assumption that the original > values are UTC time. That's one I encounter a lot. It was such a conversion that motivated me to add the no-rewrite ALTER TABLE ALTER TYPE support in the first place. Interesting. Support for it didn't end up in any submitted patch due to a formal problem: a protransform function shall only consult IMMUTABLE facts, but we posit that timezone==UTC is a STABLE observation. However, a protransform function can easily simplify the immutable expression "tscol AT TIME ZONE 'UTC'", avoiding a rewrite. See attached patch. Examples: begin; create table t (c timestamptz); set client_min_messages = debug1; -- rewrite: depends on timezone GUC alter table t alter c type timestamp; -- rewrite: depends on timezone GUC alter table t alter c type timestamptz; -- no rewrite: always UTC+0 alter table t alter c type timestamp using c at time zone 'UTC'; -- no rewrite: always UTC+0 alter table t alter c type timestamptz using c at time zone 'Etc/Universal'; -- rewrite: always UTC+0 in the present day, but not historically alter table t alter c type timestamp using c at time zone 'Atlantic/Reykjavik'; -- rewrite: always UTC+0 in the present day, but not historically alter table t alter c type timestamptz using c at time zone 'Africa/Lome'; -- no rewrite: always UTC+0 alter table t alter c type timestamp using c at time zone 'GMT'; -- rewrite: always UTC+1 alter table t alter c type timestamptz using c at time zone '1 hour'::interval; -- no rewrite: always UTC+0 alter table t alter c type timestamp using c at time zone '0 hour'::interval; rollback;
Commits
-
Avoid some table rewrites for ALTER TABLE .. SET DATA TYPE timestamp.
- 3c5926301aea 12.0 landed
-
Disable transforms that replaced AT TIME ZONE with RelabelType.
- c22ecc6562aa 10.0 cited
-
Add transform functions for AT TIME ZONE.
- b8a18ad4850e 9.5.0 cited