]> granicus.if.org Git - postgresql/commitdiff
interval: tighten precision specification
authorBruce Momjian <bruce@momjian.us>
Sat, 18 Oct 2014 14:31:00 +0000 (10:31 -0400)
committerBruce Momjian <bruce@momjian.us>
Sat, 18 Oct 2014 14:31:00 +0000 (10:31 -0400)
interval precision can only be specified after the "interval" keyword if
no units are specified.

Previously we incorrectly checked the units to see if the precision was
legal, causing confusion.

Report by Alvaro Herrera

src/backend/parser/gram.y
src/test/regress/expected/interval.out
src/test/regress/sql/interval.sql

index c98c27a16d95f8811909850ae0ad7b1a7c18c22f..0de9584e5315f312e81413897eaaeb3d5f987ea7 100644 (file)
@@ -1552,27 +1552,11 @@ zone_value:
                                        t->typmods = $3;
                                        $$ = makeStringConstCast($2, @2, t);
                                }
-                       | ConstInterval '(' Iconst ')' Sconst opt_interval
+                       | ConstInterval '(' Iconst ')' Sconst
                                {
                                        TypeName *t = $1;
-                                       if ($6 != NIL)
-                                       {
-                                               A_Const *n = (A_Const *) linitial($6);
-                                               if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
-                                                                        parser_errposition(@6)));
-                                               if (list_length($6) != 1)
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("interval precision specified twice"),
-                                                                        parser_errposition(@1)));
-                                               t->typmods = lappend($6, makeIntConst($3, @3));
-                                       }
-                                       else
-                                               t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
-                                                                                               makeIntConst($3, @3));
+                                       t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
+                                                                                       makeIntConst($3, @3));
                                        $$ = makeStringConstCast($5, @5, t);
                                }
                        | NumericOnly                                                   { $$ = makeAConst($1, @1); }
@@ -10582,21 +10566,11 @@ SimpleTypename:
                                        $$ = $1;
                                        $$->typmods = $2;
                                }
-                       | ConstInterval '(' Iconst ')' opt_interval
+                       | ConstInterval '(' Iconst ')'
                                {
                                        $$ = $1;
-                                       if ($5 != NIL)
-                                       {
-                                               if (list_length($5) != 1)
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("interval precision specified twice"),
-                                                                        parser_errposition(@1)));
-                                               $$->typmods = lappend($5, makeIntConst($3, @3));
-                                       }
-                                       else
-                                               $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
-                                                                                                makeIntConst($3, @3));
+                                       $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
+                                                                                        makeIntConst($3, @3));
                                }
                ;
 
@@ -12923,21 +12897,11 @@ AexprConst: Iconst
                                        t->typmods = $3;
                                        $$ = makeStringConstCast($2, @2, t);
                                }
-                       | ConstInterval '(' Iconst ')' Sconst opt_interval
+                       | ConstInterval '(' Iconst ')' Sconst
                                {
                                        TypeName *t = $1;
-                                       if ($6 != NIL)
-                                       {
-                                               if (list_length($6) != 1)
-                                                       ereport(ERROR,
-                                                                       (errcode(ERRCODE_SYNTAX_ERROR),
-                                                                        errmsg("interval precision specified twice"),
-                                                                        parser_errposition(@1)));
-                                               t->typmods = lappend($6, makeIntConst($3, @3));
-                                       }
-                                       else
-                                               t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
-                                                                                               makeIntConst($3, @3));
+                                       t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
+                                                                                       makeIntConst($3, @3));
                                        $$ = makeStringConstCast($5, @5, t);
                                }
                        | TRUE_P
index cf20506bc1e373307a8f1113a5ddc96cbb2b6d8b..c873a99bd94b931930b650dd9c84340d2ee5c0db 100644 (file)
@@ -616,16 +616,6 @@ SELECT interval '12:34.5678' minute to second(2);  -- per SQL spec
  00:12:34.57
 (1 row)
 
-SELECT interval(2) '12:34.5678' minute to second;  -- historical PG
-  interval   
--------------
- 00:12:34.57
-(1 row)
-
-SELECT interval(2) '12:34.5678' minute to second(2);  -- syntax error
-ERROR:  interval precision specified twice
-LINE 1: SELECT interval(2) '12:34.5678' minute to second(2);
-               ^
 SELECT interval '1.234' second;
    interval   
 --------------
index 23189174701ed59c268207a7fef2162aa96bf792..789c3de44032c35b26ba67e6029f9efbe91daffe 100644 (file)
@@ -183,8 +183,6 @@ SELECT interval '123 2:03 -2:04'; -- not ok, redundant hh:mm fields
 SELECT interval(0) '1 day 01:23:45.6789';
 SELECT interval(2) '1 day 01:23:45.6789';
 SELECT interval '12:34.5678' minute to second(2);  -- per SQL spec
-SELECT interval(2) '12:34.5678' minute to second;  -- historical PG
-SELECT interval(2) '12:34.5678' minute to second(2);  -- syntax error
 SELECT interval '1.234' second;
 SELECT interval '1.234' second(2);
 SELECT interval '1 2.345' day to second(2);