Re: [GENERAL] Why extract( ... from timestamp ) is not immutable?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: depesz(at)depesz(dot)com, pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [GENERAL] Why extract( ... from timestamp ) is not immutable?
Date: 2012-08-27 20:23:00
Message-ID: 8626.1346098980@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> On Wed, Jan 25, 2012 at 11:30:49AM -0500, Tom Lane wrote:
>> hubert depesz lubaczewski <depesz(at)depesz(dot)com> writes:
> anyway - the point is that in \df date_part(, timestamp) says it's
> immutable, while it is not.
>>
>> Hmm, you're right. I thought we'd fixed that way back when, but
>> obviously not. Or maybe the current behavior of the epoch case
>> postdates that.

> Has this been addressed?

Yes:

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Branch: master Release: REL9_2_BR [0d9819f7e] 2012-04-10 12:04:42 -0400

Measure epoch of timestamp-without-time-zone from local not UTC midnight.

This patch reverts commit 191ef2b407f065544ceed5700e42400857d9270f
and thereby restores the pre-7.3 behavior of EXTRACT(EPOCH FROM
timestamp-without-tz). Per discussion, the more recent behavior was
misguided on a couple of grounds: it makes it hard to get a
non-timezone-aware epoch value for a timestamp, and it makes this one
case dependent on the value of the timezone GUC, which is incompatible
with having timestamp_part() labeled as immutable.

The other behavior is still available (in all releases) by explicitly
casting the timestamp to timestamp with time zone before applying EXTRACT.

This will need to be called out as an incompatible change in the 9.2
release notes. Although having mutable behavior in a function marked
immutable is clearly a bug, we're not going to back-patch such a change.

The description of this in the 9.2 release notes could perhaps use some
refinement though.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2012-08-27 20:46:32 Documentation of Implicit Function Call /w Composite Types
Previous Message Pavel Stehule 2012-08-27 17:35:55 Re: GRANT SELECT

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-08-27 20:29:46 Re: FATAL: bogus data in lock file "postmaster.pid": ""
Previous Message Bruce Momjian 2012-08-27 20:22:34 Re: Optimize referential integrity checks (todo item)