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

From Karsten Hilbert
Subject Re: Why *exactly* is date_trunc() not immutable ?
Date
Msg-id 20070218114451.GK5088@merkur.hilbert.loc
Whole thread Raw
In response to Why *exactly* is date_trunc() not immutable ?  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: Why *exactly* is date_trunc() not immutable ?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Why *exactly* is date_trunc() not immutable ?  ("jungmin shin" <jungmin.shin@gmail.com>)
List pgsql-general
followup to self:

On Sun, Feb 18, 2007 at 12:29:17PM +0100, Karsten Hilbert wrote:

> So I figured it would make sense to add a functional index
> on date_trunc('day', dob) to the patients table. Which
> worked (appeared to, at least) with PG 7.4.
>
> One of our users is on PG 8.2
PostgreSQL 8.1 I was to say.

> and gets the warning that
> date_trunc() is not immutable and can thus not be used in a
> functional index.
The code to create the index:

    create index idx_identity_dob_ymd on dem.identity(date_trunc('day', dob))

The exact error it emits:

    functions in index expression must be marked IMMUTABLE

Those were lifted from the error log without further editing.

I know that I could fake immutability by wrapping
date_trunc() in a stored procedure marked IMMUTABLE but
I wonder what pitfalls that might hold.

Thanks,
Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Why *exactly* is date_trunc() not immutable ?
Next
From: Michael Glaesemann
Date:
Subject: Re: Why *exactly* is date_trunc() not immutable ?