From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ron Mayer <rm_pg@cheapcomplexdevices.com>
Cc: Sebastien FLAESCH <sf@4js.com>
Cc: pgsql-general@postgresql.org
Cc: mmoncure@gmail.com
Subject: Re: INTERVAL SECOND limited to 59 seconds?
Date: Tue, 09 Jun 2009 18:41:39 -0400
Message-ID: <208.1244587299@sss.pgh.pa.us> (raw)
In-Reply-To: <4A2DABF5.3070906@cheapcomplexdevices.com>
References: <4A127038.3010103@4js.com>
<4A2C0E02.9070908@cheapcomplexdevices.com>
<17203.1244402910@sss.pgh.pa.us>
<4A2DABF5.3070906@cheapcomplexdevices.com>
Ron Mayer <rm_pg@cheapcomplexdevices.com> writes:
> Tom Lane wrote:
>> That is a bit odd, especially seeing that eg. '1' hour to second
>> comes out as 1 second. What's making it do that?
> 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?
Well, remember that that code is dealing with an unlabeled rightmost
field. In all the cases except DAY TO MINUTE and DAY TO SECOND, the
choice is to assume that such a field corresponds to the rightmost field
of the declared interval type. So the question is do we want the
current behavior, or do we want to rearrange the switch() so that these
two cases assume MINUTE and SECOND respectively? It's certainly a
trivial code change, but it's not clear what's the right thing.
The cases of interest seem to be outside the spec, so it's not much
help. It says that
22) Let N be the number of <primary datetime field>s in the
precision of the <interval literal>, as specified by <interval
qualifier>.
The <interval literal> being defined shall contain N datetime
components.
and the syntaxes for multi-component literals are mostly not very
ambiguous --- the rightmost component is generally supposed to have
punctuation that disambiguates what it is.
I'm inclined to say that these two cases are out of line with what
the rest of the code does and we should change them. It's a judgement
call, but I can't offhand see a case where the current behavior wouldn't
seem surprising.
Plan C would be to say that these cases are ambiguous and we should
throw error. I'm not too thrilled with that, though, especially since
we didn't throw error in prior versions.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, rm_pg@cheapcomplexdevices.com, sf@4js.com, pgsql-general@postgresql.org, mmoncure@gmail.com
Subject: Re: INTERVAL SECOND limited to 59 seconds?
In-Reply-To: <208.1244587299@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox