Skip to content

Commit e6f7fe9

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 2eb60c5 commit e6f7fe9

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

src/backend/parser/gram.y

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ static Node *makeBitStringConst(char *str, int location);
118118
static Node *makeNullAConst(int location);
119119
static Node *makeAConst(Value *v, int location);
120120
static Node *makeBoolAConst(bool state, int location);
121-
static FuncCall *makeOverlaps(List *largs, List *rargs,
122-
int location, core_yyscan_t yyscanner);
123121
static void check_qualified_name(List *names, core_yyscan_t yyscanner);
124122
static List *check_func_name(List *names, core_yyscan_t yyscanner);
125123
static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
@@ -9912,7 +9910,26 @@ a_expr: c_expr { $$ = $1; }
99129910
}
99139911
| row OVERLAPS row
99149912
{
9915-
$$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
9913+
FuncCall *n = makeNode(FuncCall);
9914+
n->funcname = SystemFuncName("overlaps");
9915+
if (list_length($1) != 2)
9916+
ereport(ERROR,
9917+
(errcode(ERRCODE_SYNTAX_ERROR),
9918+
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
9919+
parser_errposition(@1)));
9920+
if (list_length($3) != 2)
9921+
ereport(ERROR,
9922+
(errcode(ERRCODE_SYNTAX_ERROR),
9923+
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
9924+
parser_errposition(@3)));
9925+
n->args = list_concat($1, $3);
9926+
n->agg_order = NIL;
9927+
n->agg_star = FALSE;
9928+
n->agg_distinct = FALSE;
9929+
n->func_variadic = FALSE;
9930+
n->over = NULL;
9931+
n->location = @2;
9932+
$$ = (Node *)n;
99169933
}
99179934
| a_expr IS TRUE_P %prec IS
99189935
{
@@ -12465,39 +12482,6 @@ makeBoolAConst(bool state, int location)
1246512482
return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
1246612483
}
1246712484

12468-
/* makeOverlaps()
12469-
* Create and populate a FuncCall node to support the OVERLAPS operator.
12470-
*/
12471-
static FuncCall *
12472-
makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
12473-
{
12474-
FuncCall *n = makeNode(FuncCall);
12475-
12476-
n->funcname = SystemFuncName("overlaps");
12477-
if (list_length(largs) == 1)
12478-
largs = lappend(largs, largs);
12479-
else if (list_length(largs) != 2)
12480-
ereport(ERROR,
12481-
(errcode(ERRCODE_SYNTAX_ERROR),
12482-
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
12483-
parser_errposition(location)));
12484-
if (list_length(rargs) == 1)
12485-
rargs = lappend(rargs, rargs);
12486-
else if (list_length(rargs) != 2)
12487-
ereport(ERROR,
12488-
(errcode(ERRCODE_SYNTAX_ERROR),
12489-
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
12490-
parser_errposition(location)));
12491-
n->args = list_concat(largs, rargs);
12492-
n->agg_order = NIL;
12493-
n->agg_star = FALSE;
12494-
n->agg_distinct = FALSE;
12495-
n->func_variadic = FALSE;
12496-
n->over = NULL;
12497-
n->location = location;
12498-
return n;
12499-
}
12500-
1250112485
/* check_qualified_name --- check the result of qualified_name production
1250212486
*
1250312487
* It's easiest to let the grammar production for qualified_name allow

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy