Interval input: usec, msec - Mailing list pgsql-patches

From Neil Conway
Subject Interval input: usec, msec
Date
Msg-id 1180327472.6152.16.camel@goldbach
Whole thread Raw
Responses Re: Interval input: usec, msec  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
neilc=# select '1 day 1 millisecond'::interval;
      interval
--------------------
 1 day 00:00:00.001
(1 row)
neilc=# select '1 millisecond'::interval;
ERROR:  invalid input syntax for type interval: "1 millisecond"
neilc=# select '0.001 seconds'::interval;
   interval
--------------
 00:00:00.001
(1 row)

Similarly for "microsecond".

I think allowing the first input but not the second is pretty
inconsistent. Attached is a patch that fixes this for both milliseconds
and microseconds. The previous coding allowed "x seconds y milliseconds"
to be specified, so this patch preserves that behavior. It *also* allows
"x seconds y seconds" as valid input, although you could make a
consistency argument for that anyway: (with CVS HEAD, unpatched)

neilc=# select '5 days 10 days'::interval;
 interval
----------
 15 days
neilc=# select '1 week 2 week 3 weeks'::interval;
 interval
----------
 42 days
neilc=# select '1 second 2 second'::interval;
ERROR:  invalid input syntax for type interval: "1 second 2 second"

Is there any reason to why DecodeInterval() is willing to accept
multiple specifications for some time units but not others?

-Neil


Attachment

pgsql-patches by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Re: Maintaining cluster order on insert
Next
From: Tom Lane
Date:
Subject: Re: Interval input: usec, msec