Re: Interval+tz-tz gives unexpected result - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Interval+tz-tz gives unexpected result
Date
Msg-id 2793.1037034592@sss.pgh.pa.us
Whole thread Raw
In response to Interval+tz-tz gives unexpected result  ("Henshall, Stuart - Design & Print" <SHenshall@westcountry-design-print.co.uk>)
List pgsql-bugs
"Henshall, Stuart - Design & Print" <SHenshall@westcountry-design-print.co.uk> writes:
> dev=# select '0 sec'::interval+'2002/10/21 09:48'::timestamptz-'2002/10/21
> 09:30'::timestamptz;
>  ?column?
> ----------
>  -09:30
> (1 row)

In 7.3 I get

regression=# select '0 sec'::interval+'2002/10/21 09:48'::timestamptz-'2002/10/21 09:30'::timestamptz;
ERROR:  Unable to identify an operator '+' for types 'interval' and 'timestamp with time zone'
        You will have to retype this query using an explicit cast

I'm not sure what interpretation 7.2 is putting on this, but I see that
the addition is yielding a timestamp without time zone:

regression=# select '0 sec'::interval+'2002/10/21 09:48'::timestamptz;
      ?column?
---------------------
 2002-10-21 00:00:00
(1 row)

I *think* it may be coercing the inputs so it can use the date + time
without timezone operator.  Which is a tad silly.  We've tightened up
the implicit coercions for 7.3, which is why it doesn't do this anymore.

In the meantime, the real issue for you is that there's a timestamptz +
interval operator, but not interval + timestamptz, so you need to recast
the command as timestamptz + interval - timestamptz.

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Henshall, Stuart - Design & Print"
Date:
Subject: Interval+tz-tz gives unexpected result
Next
From: Pavel Stehule
Date:
Subject: PG_RETURN_TEXT_P crash server process