Re: interval typmodout is broken - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: interval typmodout is broken
Date
Msg-id 20140924213259.GU5311@eldon.alvh.no-ip.org
Whole thread Raw
In response to Re: interval typmodout is broken  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: interval typmodout is broken
List pgsql-hackers
Tom Lane wrote:
> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > I just noticed when working on DDL deparsing that the typmodout routine
> > for intervals is broken.  The code uses
> 
> >     if (precision != INTERVAL_FULL_PRECISION)
> >         snprintf(res, 64, "%s(%d)", fieldstr, precision);
> >     else
> >         snprintf(res, 64, "%s", fieldstr);
> 
> > which puts the parenthised number after the textual name; but the
> > grammar only takes it the other way around.
> 
> You sure about that?  The grammar for INTERVAL is weird.  I believe
> the output we're trying to produce here is something like
> 
>     INTERVAL HOUR TO SECOND(2)
> 
> where "fieldstr" would be " HOUR TO SECOND" and "precision" would
> give the fractional-second precision.

Well, I tested what is taken on input, and yes I agree the grammar is
weird (but not more weird than timestamp/timestamptz, mind).  The input
function only accepts the precision just after the INTERVAL keyword, not
after the fieldstr:

alvherre=# create table str (a interval(2) hour to minute);
CREATE TABLE

alvherre=# create table str2 (a interval hour to minute(2));
ERROR:  syntax error at or near "("
LÍNEA 1: create table str2 (a interval hour to minute(2));                                                    ^



-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: Review of GetUserId() Usage
Next
From: Tom Lane
Date:
Subject: Sloppy thinking about leakproof properties of opclass co-members