pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: Sachin Srivastava <sachin.srivastava@enterprisedb.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: timestamp issue
Date: Thu, 17 Feb 2011 09:58:32 -0500
Message-ID: <6624.1297954712@sss.pgh.pa.us> (raw)
In-Reply-To: <4D5CD167.10908@enterprisedb.com>
References: <379DB7E6-D1DD-4ADB-9454-5D67E9BF416D@enterprisedb.com>
	<4D5CD167.10908@enterprisedb.com>

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



view thread (3+ messages)

Message-ID: <6624.1297954712@sss.pgh.pa.us>
Permalink:  ../6624.1297954712@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6624.1297954712@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, heikki.linnakangas@enterprisedb.com, sachin.srivastava@enterprisedb.com
  Subject: Re: timestamp issue
  In-Reply-To: <6624.1297954712@sss.pgh.pa.us>
  References: <379DB7E6-D1DD-4ADB-9454-5D67E9BF416D@enterprisedb.com> <4D5CD167.10908@enterprisedb.com> <6624.1297954712@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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