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