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

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Why *exactly* is date_trunc() not immutable ?
Date: 2007-02-19 09:58:50
Message-ID: 20070219095850.GC30737@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Primero Segundo 2007-02-19 10:19:48 RE: Postgresql 8.1 y Debian [ Era: Re: postgreSQL ]
Previous Message Karsten Hilbert 2007-02-19 09:36:36 Re: Why *exactly* is date_trunc() not immutable ?