Re: Why *exactly* is date_trunc() not immutable ?

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Why *exactly* is date_trunc() not immutable ?
Date: 2007-02-19 09:11:54
Message-ID: 9D213BD2-5427-44AC-B916-355E03CE709C@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Feb 18, 2007, at 23:12 , Karsten Hilbert wrote:

> On Sun, Feb 18, 2007 at 09:19:43PM +0900, Michael Glaesemann wrote:
>
>>> What I don't understand, however, is exactly *why* date_trunc is
>>> not immutable ?
>>
>> I believe it's because the result of date_trunc depends on the time
>> zone setting for the session.
>
> ...
>
>> So, given the same arguments, ('day', and current_timestamp),
>> date_trunc is returning two different results. (Casting to date has
>> the same issue.)
>
> Ah, I see. That makes sense.
>
> Now, if I'd write a
>
> date_trunc_utc(precision, timestamp with time zone)
>
> which converts input timestamps to UTC I could fairly safely
> mark that IMMUTABLE, no ?

Yeah, I think if you normalized it to UTC you could mark your new
function as immutable.

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2007-02-19 09:12:42 Re: complex referential integrity constraints
Previous Message Michael Glaesemann 2007-02-19 09:10:56 Re: Why *exactly* is date_trunc() not immutable ?