BUG #7498: Questionable interval parsing when in the form 'n m days'
BUG #7498: Questionable interval parsing when in the form 'n m days'
От:
daniel@heroku.com
Дата:
The following bug has been logged on the website:
Bug reference: 7498
Logged by: Daniel Farina
Email address: daniel@heroku.com
PostgreSQL version: 9.1.4
Operating system: Ubuntu 12.04
Description: =
This is an expression that should probably have an error and not evaluate to
"true":
select '1 5 hours'::interval =3D '1 day 5 hours'::interval;
?column? =
----------
t
(1 row)
I think that the first spelling, a unit-less '1', should not be accepted. =
Other unit combinations agree:
select '1 5 minutes'::interval;
ERROR: invalid input syntax for type interval: "1 5 minutes"
LINE 1: select '1 5 minutes'::interval;
^
select '1 5 months'::interval;
ERROR: invalid input syntax for type interval: "1 5 months"
LINE 1: select '1 5 months'::interval;
^
select '1 5 seconds'::interval;
ERROR: invalid input syntax for type interval: "1 5 seconds"
LINE 1: select '1 5 seconds'::interval;Re: BUG #7498: Questionable interval parsing when in the form 'n m days'
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
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. regards, tom lane
Re: BUG #7498: Questionable interval parsing when in the form 'n m days'
От:
Daniel Farina <daniel@heroku.com>
Дата:
On Wed, Aug 15, 2012 at 5:19 PM, Tom Lane 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