Re: Interval constant syntax, was Re: Interval & check clause - Mailing list pgsql-general

From Tom Lane
Subject Re: Interval constant syntax, was Re: Interval & check clause
Date
Msg-id 27508.1080625348@sss.pgh.pa.us
Whole thread Raw
In response to Re: Interval constant syntax, was Re: Interval & check clause  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
Bruno Wolff III <bruno@wolff.to> writes:
> This is different in that you are using - instead of >= . Date - Date
> will get picked because that is the only - operator with a left operand
> of type date.

Even if it weren't the only one, there is a preferential case involved:
given "known_type operator unknown_literal", the parser will
preferentially assume that the unknown_literal is the same type as the
other operand, if there is an available operator that takes that type
on both sides.  For details see
    http://www.postgresql.org/docs/7.4/static/typeconv-oper.html
(rule 2a is my point here).

Note that in *no* case will the contents of the string literal have any
a-priori effect on the parser's decision about what the literal's type
is.  I believe this is a good policy in general --- doing otherwise
would render the behavior way too unpredictable, since often the
contents of the literal are not under the control of the SQL query
author.  But this does mean that just writing '2 days' is not going
to be enough to make the system think it is an interval constant.
There must be some cue to the type outside the quotes, whether an
explicit cast or an implicit match to another operand.

            regards, tom lane

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Interval constant syntax, was Re: Interval & check clause
Next
From: Shanmugasundaram Doraisamy
Date:
Subject: Can we have time based triggers in Postgresql??