On Wed, Aug 15, 2012 at 5:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> daniel@heroku.com writes:
>> select '1 5 hours'::interval = '1 day 5 hours'::interval;
>> ?column?
>> ----------
>> t
>> (1 row)
>
>> I think that the first spelling, a unit-less '1', should not be accepted.
>
> Not sure I agree. The syntax '1 05:00' is required by spec to mean
> '1 day 5 hours 0 minutes'. I would take that to mean that a unitless
> number directly to the left of an hours field is days. Anyway, the
> code in DecodeInterval is treating these cases the same.
Interesting. I see your point, but I think that a user writing a
symbolic name of the unit is probably different than the one relying
on '1 05:00'. My reasoning is that without any units specified that
what one has is a syntax that is contingent on position, whereas the
symbolic units are not:
select '3 minute 1 day'::interval = '1 day 3 minute'::interval;
And I think that's why '1 5 hours' is funny looking vs '1 5:00', borne
out more by the confusion as to why 'hours' is given this special
status but any other unit that I have tried is not. It also reads
much closer to "15 hours" than "1 5:00" does in my opinion.
I am hard pressed to imagine a person who would prefer the 'M N hours'
variant of the notation be accepted, but perhaps that is more of a
general problem with the positional syntax...consider:
select '1 5:'::interval = '1 day 5 hours'::interval;
Whereby the valid interval string is "1 5:".
--
fdr