Tom Lane wrote:
> support for SQL-spec interval literals. I decided to go look at exactly
> how unfinished it was, and it turns out that it's actually pretty close.
> Hence the attached proposed patch ;-)
Is this code handling negative interval literals right?
I think I quote the relevant spec part at the bottom.
If I'm reading the spec right, I find this surprising.
regression=# select interval '-1-1'; interval
------------------- -1 days -01:00:00
regression=# select interval '1-1'; interval
-------------- 1 year 1 mon
Also if I read the spec right, ISTM the <sign> should
apply to the entire interval literal. But if I compiled
the patch right, the negative sign applies only to the
first part it encounters?
regression=# select interval '-1 2:3:4'; interval
------------------- -1 days +02:03:04
(1 row)
If I understand right, this'll add confusion to
SQL "standard" output for mixed year-month and
day-time intervals that have both negative and
positive components too. :(
This looks to me like the relevant part of SQL 200N(8?),
which seems to me to allow a sign inside the quotes:
====================================================================
<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> }
====================================================================