Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 417f924

Browse files
committed
interval: tighten precision specification
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
1 parent 97d5548 commit 417f924

File tree

3 files changed

+9
-57
lines changed

3 files changed

+9
-57
lines changed

src/backend/parser/gram.y

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,27 +1552,11 @@ zone_value:
15521552
t->typmods = $3;
15531553
$$ = makeStringConstCast($2, @2, t);
15541554
}
1555-
| ConstInterval '(' Iconst ')' Sconst opt_interval
1555+
| ConstInterval '(' Iconst ')' Sconst
15561556
{
15571557
TypeName *t = $1;
1558-
if ($6 != NIL)
1559-
{
1560-
A_Const *n = (A_Const *) linitial($6);
1561-
if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
1562-
ereport(ERROR,
1563-
(errcode(ERRCODE_SYNTAX_ERROR),
1564-
errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
1565-
parser_errposition(@6)));
1566-
if (list_length($6) != 1)
1567-
ereport(ERROR,
1568-
(errcode(ERRCODE_SYNTAX_ERROR),
1569-
errmsg("interval precision specified twice"),
1570-
parser_errposition(@1)));
1571-
t->typmods = lappend($6, makeIntConst($3, @3));
1572-
}
1573-
else
1574-
t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1575-
makeIntConst($3, @3));
1558+
t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
1559+
makeIntConst($3, @3));
15761560
$$ = makeStringConstCast($5, @5, t);
15771561
}
15781562
| NumericOnly { $$ = makeAConst($1, @1); }
@@ -10582,21 +10566,11 @@ SimpleTypename:
1058210566
$$ = $1;
1058310567
$$->typmods = $2;
1058410568
}
10585-
| ConstInterval '(' Iconst ')' opt_interval
10569+
| ConstInterval '(' Iconst ')'
1058610570
{
1058710571
$$ = $1;
10588-
if ($5 != NIL)
10589-
{
10590-
if (list_length($5) != 1)
10591-
ereport(ERROR,
10592-
(errcode(ERRCODE_SYNTAX_ERROR),
10593-
errmsg("interval precision specified twice"),
10594-
parser_errposition(@1)));
10595-
$$->typmods = lappend($5, makeIntConst($3, @3));
10596-
}
10597-
else
10598-
$$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10599-
makeIntConst($3, @3));
10572+
$$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
10573+
makeIntConst($3, @3));
1060010574
}
1060110575
;
1060210576

@@ -12923,21 +12897,11 @@ AexprConst: Iconst
1292312897
t->typmods = $3;
1292412898
$$ = makeStringConstCast($2, @2, t);
1292512899
}
12926-
| ConstInterval '(' Iconst ')' Sconst opt_interval
12900+
| ConstInterval '(' Iconst ')' Sconst
1292712901
{
1292812902
TypeName *t = $1;
12929-
if ($6 != NIL)
12930-
{
12931-
if (list_length($6) != 1)
12932-
ereport(ERROR,
12933-
(errcode(ERRCODE_SYNTAX_ERROR),
12934-
errmsg("interval precision specified twice"),
12935-
parser_errposition(@1)));
12936-
t->typmods = lappend($6, makeIntConst($3, @3));
12937-
}
12938-
else
12939-
t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
12940-
makeIntConst($3, @3));
12903+
t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
12904+
makeIntConst($3, @3));
1294112905
$$ = makeStringConstCast($5, @5, t);
1294212906
}
1294312907
| TRUE_P

src/test/regress/expected/interval.out

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,6 @@ SELECT interval '12:34.5678' minute to second(2); -- per SQL spec
616616
00:12:34.57
617617
(1 row)
618618

619-
SELECT interval(2) '12:34.5678' minute to second; -- historical PG
620-
interval
621-
-------------
622-
00:12:34.57
623-
(1 row)
624-
625-
SELECT interval(2) '12:34.5678' minute to second(2); -- syntax error
626-
ERROR: interval precision specified twice
627-
LINE 1: SELECT interval(2) '12:34.5678' minute to second(2);
628-
^
629619
SELECT interval '1.234' second;
630620
interval
631621
--------------

src/test/regress/sql/interval.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ SELECT interval '123 2:03 -2:04'; -- not ok, redundant hh:mm fields
183183
SELECT interval(0) '1 day 01:23:45.6789';
184184
SELECT interval(2) '1 day 01:23:45.6789';
185185
SELECT interval '12:34.5678' minute to second(2); -- per SQL spec
186-
SELECT interval(2) '12:34.5678' minute to second; -- historical PG
187-
SELECT interval(2) '12:34.5678' minute to second(2); -- syntax error
188186
SELECT interval '1.234' second;
189187
SELECT interval '1.234' second(2);
190188
SELECT interval '1 2.345' day to second(2);

0 commit comments

Comments
 (0)