From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Phil Couling <couling(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Error: timestamp with timezone + interval is not immutable while creating index |
Date: | 2011-10-13 23:32:54 |
Message-ID: | 7034.1318548774@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Phil Couling <couling(at)gmail(dot)com> writes:
> main=> create index foo_next_update on foo( (last_updated + update_cycle) ) ;
> ERROR: functions in index expression must be marked IMMUTABLE
> Does anyone know why adding two fields like this results in anything
> other than an immutable function? Under what circumstances could it
> return a different result?
timestamptz + interval is not immutable because the results can vary
depending on timezone. For instance, in my zone (America/New_York):
regression=# select '2011-11-06 00:00'::timestamptz;
timestamptz
------------------------
2011-11-06 00:00:00-04
(1 row)
regression=# select '2011-11-06 00:00'::timestamptz + '1 day'::interval;
?column?
------------------------
2011-11-07 00:00:00-05
(1 row)
regression=# select '2011-11-06 00:00'::timestamptz + '24 hours'::interval;
?column?
------------------------
2011-11-06 23:00:00-05
(1 row)
In a zone where that day wasn't a DST transition day, you'd get
different results. IOW, adding '1 day' can mean 23, 24, or 25 hours
depending on your zone and the particular date.
If the interval value doesn't contain any days or months or larger
components, then yeah, the sum would be immutable ... but unfortunately
there's no way to express that concept given the particular datatypes
we've got.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Anthony Presley | 2011-10-13 23:33:57 | Re: Drill-downs and OLAP type data |
Previous Message | David Salisbury | 2011-10-13 23:19:00 | Re: Error: timestamp with timezone + interval is not immutable while creating index |