Re: problem creating rtree index on timestamptz - Mailing list pgsql-bugs

From Tom Lane
Subject Re: problem creating rtree index on timestamptz
Date
Msg-id 2876.1109628785@sss.pgh.pa.us
Whole thread Raw
In response to problem creating rtree index on timestamptz  (Hussein Patni <security@cosbit.com>)
List pgsql-bugs
Hussein Patni <security@cosbit.com> writes:
> It seems subraction of an interval from a
> timestamptz is not immutable. Should this be the case?

Yes, because the results depend on your local timezone.  For example:

regression=# set TimeZone TO 'EST5EDT';
SET
regression=# select '2005-02-28 17:00-05'::timestamptz - '6 months'::interval;
        ?column?
------------------------
 2004-08-28 17:00:00-04
(1 row)

regression=# set TimeZone TO 'GMT';
SET
regression=# select '2005-02-28 17:00-05'::timestamptz - '6 months'::interval;
        ?column?
------------------------
 2004-08-28 22:00:00+00
(1 row)

regression=# select '2004-08-28 17:00:00-04'::timestamptz - '2004-08-28 22:00:00+00';
 ?column?
-----------
 -01:00:00
(1 row)

regression=#

It's probably true that subtracting an interval expressed in seconds (or
equivalent units) is an immutable operation, but we don't have a way to
capture that statement in data types, since there's no such restricted
interval datatype.

You might consider making a function defined like timestamptz - integer
(or float) in which the integer is considered as a number of seconds.
You could safely mark that as immutable, I think.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Hussein Patni
Date:
Subject: problem creating rtree index on timestamptz
Next
From: "Stephen Clouse"
Date:
Subject: BUG #1512: Assertion failure (lock.c:1537) with SELECT FOR UPDATE and savepoints