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> }
===================================================================