Re: Why *exactly* is date_trunc() not immutable ? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Why *exactly* is date_trunc() not immutable ?
Date
Msg-id 20070219095850.GC30737@svana.org
Whole thread Raw
In response to Re: Why *exactly* is date_trunc() not immutable ?  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: Why *exactly* is date_trunc() not immutable ?
List pgsql-general
On Mon, Feb 19, 2007 at 10:36:36AM +0100, Karsten Hilbert wrote:
> On Mon, Feb 19, 2007 at 10:16:12AM +0100, Alban Hertroys wrote:
>
> > What I'm trying to say is not that it _is_ immutable, but that it
> > _behaves_ immutable (under said conditions).
> >
> > This could imply that if a certain condition is available in a query on
> > which such a function operates, it would behave immutable.
> That is precisely why I didn't get the idea upfront that
> date_trunc() wouldn't be immutable just so.
>
> I'll solve it with a date_trunc_utc() wrapper.

It should be noted the date_truc(timestamptz) is not immutable, whereas
date_trunc(timestamp) is. Thus you should be able to make an index on:

date_trunc( timestamptz_column AT TIME ZONE 'UTC', 'foo' )

OTOH, if you're only storing times in UTC, then timestamp without
timezone might be better anyway.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: Why *exactly* is date_trunc() not immutable ?
Next
From: "Joris Dobbelsteen"
Date:
Subject: Re: complex referential integrity constraints