Skip to content

Commit a222f7f

Browse files
committed
Remove broken code that tried to handle OVERLAPS with a single argument.
The SQL standard says that OVERLAPS should have a two-element row constructor on each side. The original coding of OVERLAPS support in our grammar attempted to extend that by allowing a single-element row constructor, which it internally duplicated ... or tried to, anyway. But that code has certainly not worked since our List infrastructure was rewritten in 2004, and I'm none too sure it worked before that. As it stands, it ends up building a List that includes itself, leading to assorted undesirable behaviors later in the parser. Even if it worked as intended, it'd be a bit evil because of the possibility of duplicate evaluation of a volatile function that the user had written only once. Given the lack of documentation, test cases, or complaints, let's just get rid of the idea and only support the standard syntax. While we're at it, improve the error cursor positioning for the wrong-number-of-arguments errors, and inline the makeOverlaps() function since it's only called in one place anyway. Per bug #9227 from Joshua Yanovski. Initial patch by Joshua Yanovski, extended a bit by me.
1 parent 7f3e17b commit a222f7f

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/backend/parser/gram.y

+13-28
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ static Node *makeBitStringConst(char *str, int location);
136136
static Node *makeNullAConst(int location);
137137
static Node *makeAConst(Value *v, int location);
138138
static Node *makeBoolAConst(bool state, int location);
139-
static FuncCall *makeOverlaps(List *largs, List *rargs,
140-
int location, core_yyscan_t yyscanner);
141139
static void check_qualified_name(List *names, core_yyscan_t yyscanner);
142140
static List *check_func_name(List *names, core_yyscan_t yyscanner);
143141
static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
@@ -10949,7 +10947,19 @@ a_expr: c_expr { $$ = $1; }
1094910947
}
1095010948
| row OVERLAPS row
1095110949
{
10952-
$$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
10950+
if (list_length($1) != 2)
10951+
ereport(ERROR,
10952+
(errcode(ERRCODE_SYNTAX_ERROR),
10953+
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10954+
parser_errposition(@1)));
10955+
if (list_length($3) != 2)
10956+
ereport(ERROR,
10957+
(errcode(ERRCODE_SYNTAX_ERROR),
10958+
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10959+
parser_errposition(@3)));
10960+
$$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
10961+
list_concat($1, $3),
10962+
@2);
1095310963
}
1095410964
| a_expr IS TRUE_P %prec IS
1095510965
{
@@ -13397,31 +13407,6 @@ makeBoolAConst(bool state, int location)
1339713407
return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
1339813408
}
1339913409

13400-
/* makeOverlaps()
13401-
* Create and populate a FuncCall node to support the OVERLAPS operator.
13402-
*/
13403-
static FuncCall *
13404-
makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
13405-
{
13406-
FuncCall *n;
13407-
if (list_length(largs) == 1)
13408-
largs = lappend(largs, largs);
13409-
else if (list_length(largs) != 2)
13410-
ereport(ERROR,
13411-
(errcode(ERRCODE_SYNTAX_ERROR),
13412-
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
13413-
parser_errposition(location)));
13414-
if (list_length(rargs) == 1)
13415-
rargs = lappend(rargs, rargs);
13416-
else if (list_length(rargs) != 2)
13417-
ereport(ERROR,
13418-
(errcode(ERRCODE_SYNTAX_ERROR),
13419-
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
13420-
parser_errposition(location)));
13421-
n = makeFuncCall(SystemFuncName("overlaps"), list_concat(largs, rargs), location);
13422-
return n;
13423-
}
13424-
1342513410
/* check_qualified_name --- check the result of qualified_name production
1342613411
*
1342713412
* It's easiest to let the grammar production for qualified_name allow

0 commit comments

Comments
 (0)