Re: timestamp issue - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject Re: timestamp issue
Date
Msg-id 4D5CD167.10908@enterprisedb.com
Whole thread Raw
In response to timestamp issue  (Sachin Srivastava <sachin.srivastava@enterprisedb.com>)
Responses Re: timestamp issue
List pgsql-bugs
On 17.02.2011 08:06, Sachin Srivastava wrote:
> postgres=# SELECT now() + '7 days' AS week_ahead;
>              week_ahead
> ----------------------------------
>   2011-02-24 10:39:29.951931+05:30
> (1 row)
>
> postgres=# SELECT now() - '7 days' AS week_behind;
> ERROR:  invalid input syntax for type timestamp with time zone: "7 days"
> LINE 1: SELECT now() - '7 days' AS week_behind;
>                                              ^
>
> Now, if '+' operator  works with '7 days', why dint the '-' operator? Is this intentional or a bug?

Intentional, or at least coincidental.

postgres=# SELECT oprname, oprleft::regtype, oprright::regtype FROM
pg_operator WHERE oprleft ='timestamptz'::regtype AND oprname IN('+', '-');
  oprname |         oprleft          |         oprright
---------+--------------------------+--------------------------
  +       | timestamp with time zone | interval
  -       | timestamp with time zone | timestamp with time zone
  -       | timestamp with time zone | interval
(3 rows)

With '-', it's getting interpreted as timestamptz-timestamptz.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

pgsql-bugs by date:

Previous
From: Sachin Srivastava
Date:
Subject: timestamp issue
Next
From: Vegard Bønes
Date:
Subject: Re: BUG #5883: Error when mixing SPI_returntuple with returning regular HeapTuple