Re: Patch for SQL-Standard Interval output and decoupling DateStyle from IntervalStyle

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>, Brendan Jurd <direvus(at)gmail(dot)com>, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch for SQL-Standard Interval output and decoupling DateStyle from IntervalStyle
Date: 2008-11-04 17:55:29
Message-ID: 49108C91.9080100@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:
>> Ah. And one final question regarding functionality.
>> It seems to me that the last remaining place where we input
>> a SQL-2008 standard literal and do something different from
>> what the standard suggests is with the string:
>> '-1 2:03:04'
>> The standard seems to say that the "-" affects both the
>> days and hour/min/sec part; while PostgreSQL historically,
>> and the patch as I first submitted it only apply the negative
>> sign to the days part.
>
>> IMHO when the IntervalStyle GUC is set to "sql_standard",
>> it'd be better if the parsing of this literal matched the
>> standard.
>
> Then how would you input a value that had different signs for the
> day and the h/m/s? I don't think "you can't" is an acceptable
> answer there, because it would mean that interval_out has to fail
> on such values when IntervalStyle is "sql_standard". Which is
> very clearly not gonna do.

In the patch I submitted:
"-1 +2:03:04" always means negative day, positive hours/min/sec
"+1 -2:03:04" always means positive day, negative hours/min/sec

When given a non-standard interval value, EncodeInterval is
always outputting all the signs ("+" and "-") to force it
to be unambiguous.

-- test a couple non-standard interval values too
SELECT interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds',
- interval '1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds';
interval | ?column?
----------------------+----------------------
+1-2 -3 +4:05:06.789 | -1-2 +3 -4:05:06.789
(1 row)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-11-04 18:03:44 Re: gram.y => preproc.y
Previous Message Bernd Helmle 2008-11-04 17:55:17 Re: Patch for ALTER DATABASE WITH TABLESPACE