pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
timestamp issue
3+ messages / 3 participants
[nested] [flat]

* timestamp issue
@ 2011-02-17 06:06 Sachin Srivastava <sachin.srivastava@enterprisedb.com>
  2011-02-17 07:42 ` Re: timestamp issue Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Sachin Srivastava @ 2011-02-17 06:06 UTC (permalink / raw)
  To: pgsql-bugs

Hello all,

I am running PostgreSQL 9.0.2 on Mac (10.6.6)

This is what I get in the psql terminal:

postgres=# SELECT version();
                                                              version                                                               
------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.0.2 on x86_64-apple-darwin, compiled by GCC i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664), 64-bit
(1 row)

postgres=# SELECT now() + interval '7 days' AS week_ahead;
            week_ahead            
----------------------------------
 2011-02-24 10:39:07.071655+05:30
(1 row)

postgres=# SELECT now() - interval '7 days' AS week_behind;
           week_behind            
----------------------------------
 2011-02-10 10:39:21.848049+05:30
(1 row)

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?

--
Regards,
Sachin Srivastava
EnterpriseDB, the Enterprise PostgreSQL company.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: timestamp issue
  2011-02-17 06:06 timestamp issue Sachin Srivastava <sachin.srivastava@enterprisedb.com>
@ 2011-02-17 07:42 ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  2011-02-17 14:58   ` Re: timestamp issue Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Heikki Linnakangas @ 2011-02-17 07:42 UTC (permalink / raw)
  To: Sachin Srivastava <sachin.srivastava@enterprisedb.com>; +Cc: 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: timestamp issue
  2011-02-17 06:06 timestamp issue Sachin Srivastava <sachin.srivastava@enterprisedb.com>
  2011-02-17 07:42 ` Re: timestamp issue Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
@ 2011-02-17 14:58   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2011-02-17 14:58 UTC (permalink / raw)
  To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>; +Cc: Sachin Srivastava <sachin.srivastava@enterprisedb.com>; pgsql-bugs

Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> writes:
> On 17.02.2011 08:06, Sachin Srivastava wrote:
>> postgres=# SELECT now() - '7 days' AS week_behind;
>> ERROR:  invalid input syntax for type timestamp with time zone: "7 days"
>> 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.

To be more specific: since you didn't cast the unknown-type literal to
any particular type, the parser had to guess which operator is meant.
In a case like this it will prefer to guess that both operands are of
the same datatype.  So, knowing that now() yields timestamptz, it tried
to interpret the literal as timestamptz too.

There is no corresponding problem on the + side because there's no
timestamptz+timestamptz operator, that not being a meaningful operation.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2011-02-17 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-02-17 06:06 timestamp issue Sachin Srivastava <sachin.srivastava@enterprisedb.com>
2011-02-17 07:42 ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
2011-02-17 14:58   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox