Re: Proposed patch: make SQL interval-literal syntax work per spec - Mailing list pgsql-hackers

From Ron Mayer
Subject Re: Proposed patch: make SQL interval-literal syntax work per spec
Date
Msg-id 48CEF4E1.8040105@cheapcomplexdevices.com
Whole thread Raw
In response to Re: Proposed patch: make SQL interval-literal syntax work per spec  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> Ron Mayer <rm_pg@cheapcomplexdevices.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> }
===================================================================



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Proposed patch: make SQL interval-literal syntax work per spec
Next
From: KaiGai Kohei
Date:
Subject: Re: Proposal of SE-PostgreSQL patches (for CommitFest:Sep)