Re: Proposed patch: make SQL interval-literal syntax work per spec

From: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Proposed patch: make SQL interval-literal syntax work per spec
Date: 2008-09-15 23:50:57
Message-ID: 48CEF4E1.8040105@cheapcomplexdevices.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com> writes:
>> Is this code handling negative interval literals right?
>> I think I quote the relevant spec part at the bottom.
>
> We support independent signs for the different components of the

Even so it surprises me that:
'-1-1'::interval gives me a day-hour interval while
'1-1'::interval gives me a year-month interval.

>I'm not sure how well the spec copes with that.

If I'm read the spec right, SQL 2008 expects "-1 12:34:56" to
be what we'd see as "-1 -12:34:56", and doesn't handle with
different signs for different components at all.

SQL 92 seems to have been simpler, apparently requiring
the negative sign to stay outside the quotes.
==SQL 92===========================================================
<interval literal> ::=
INTERVAL [ <sign> ] <interval string> <interval qualifier>
<interval string> ::=
<quote> { <year-month literal> | <day-time literal> } <quote>
===================================================================

SQL 200N seems to allow a sign inside the string:
==SQL 200N=========================================================
<interval literal> ::=
INTERVAL [ <sign> ] <interval string> <interval qualifier>
<interval string> ::=
<quote> <unquoted interval string> <quote>
<unquoted interval string> ::=
[ <sign> ] { <year-month literal> | <day-time literal> }
===================================================================

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message KaiGai Kohei 2008-09-16 01:32:11 Re: Proposal of SE-PostgreSQL patches (for CommitFest:Sep)
Previous Message Tom Lane 2008-09-15 23:42:29 Re: Proposed patch: make SQL interval-literal syntax work per spec