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: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Proposed patch: make SQL interval-literal syntax work per spec
Date: 2008-09-15 23:37:32
Message-ID: 48CEF1BC.90905@cheapcomplexdevices.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-09-15 23:42:29 Re: Proposed patch: make SQL interval-literal syntax work per spec
Previous Message Tom Lane 2008-09-15 22:37:06 Coping with nLocks overflow