Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DB7071337B4F for ; Thu, 17 Feb 2011 10:58:46 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 89103-05 for ; Thu, 17 Feb 2011 14:58:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 5ECA71337B4A for ; Thu, 17 Feb 2011 10:58:39 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p1HEwWxR006625; Thu, 17 Feb 2011 09:58:32 -0500 (EST) To: Heikki Linnakangas cc: Sachin Srivastava , pgsql-bugs@postgresql.org Subject: Re: timestamp issue In-reply-to: <4D5CD167.10908@enterprisedb.com> References: <379DB7E6-D1DD-4ADB-9454-5D67E9BF416D@enterprisedb.com> <4D5CD167.10908@enterprisedb.com> Comments: In-reply-to Heikki Linnakangas message dated "Thu, 17 Feb 2011 09:42:31 +0200" Date: Thu, 17 Feb 2011 09:58:32 -0500 Message-ID: <6624.1297954712@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/157 X-Sequence-Number: 29429 Heikki Linnakangas 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