Re: INTERVAL SECOND limited to 59 seconds?

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>, Sebastien FLAESCH <sf(at)4js(dot)com>, pgsql-general(at)postgresql(dot)org, mmoncure(at)gmail(dot)com
Subject: Re: INTERVAL SECOND limited to 59 seconds?
Date: 2009-06-09 00:25:25
Message-ID: 4A2DABF5.3070906@cheapcomplexdevices.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Tom Lane wrote:
> Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com> writes:
>> Looks like the original questions from the thread
>> got resolved, but I found this behaviour surprising:
>
>> regression=# select interval '1' day to second;
>> interval
>> ----------
>> @ 1 hour
>> (1 row)
>
>> Should this be 1 second?
>
> That is a bit odd, especially seeing that eg. '1' hour to second
> comes out as 1 second. What's making it do that?

What from a design point of view? Seems like it's a side
effect of the logic that makes:
select interval '1 2';
know that the 2 means hours rather than seconds.

Code-wise, it seems because around line 2906 in DecodeInterval:
switch (range) ...
case INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE) | INTERVAL_MASK(SECOND):
type=DTK_HOUR;
But if I naively change that by making it DTK_SECOND,
I'd break "select interval '1 2' day to second;". I guess I'd need
to tweak it to say: if it follows a days filed it means hours; but
by itself it means seconds?

There's a bit of other odd stuff around there. It seems CVS head accepts
"select interval '1 2' hour;" but not "select interval '1 2' hour to minute;"
regression=# select interval '1 2' hour;
interval
----------------
1 day 02:00:00
(1 row)
and I would have guessed that either both should succeed or both should fail.
And if both succeed I wouldn't have expected 1 day 2 hours......

I'd still be happy to send a patch, but am still trying to figure out
what the desired behavior is. My current impression:

What's the desired behavior for each of these:

select interval '1' day to second;
--- should it be 1 second to be consistent with "select interval 1;"?
--- or an error as Sebastien argued in a different part of the thread?

select interval '1 2' hour;
--- should be an error as "select interval '1 2' hour to minute" is?
--- should be "1 day 2 hours" as cvs head treats
"select interval '1 day 2 hours' hour to minute;"?
--- should be 2 hours?

select interval '1 2' hour to minute;
--- should be an error as "select interval '1 2' hour to minute" is?
--- should be "1 day 2 hours" as cvs head treats
"select interval '1 day 2 hours' hour to minute;"?
--- should be 2 hours?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2009-06-09 00:31:46 Re: Why lots of temp schemas are being created
Previous Message Josh Berkus 2009-06-09 00:24:15 Streaming SFPUG: PostgreSQL & Rails June 9 (tommorrow)

Browse pgsql-hackers by date

  From Date Subject
Next Message Floris Bos / Maxnet 2009-06-09 00:32:46 Multicolumn index corruption on 8.4 beta 2
Previous Message Tom Lane 2009-06-08 23:34:56 Re: postmaster recovery and automatic restart suppression