Skip to content

Commit d7cd6a9

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 062deb3 commit d7cd6a9

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
@@ -119,8 +119,6 @@ static Node *makeBitStringConst(char *str, int location);
119119
static Node *makeNullAConst(int location);
120120
static Node *makeAConst(Value *v, int location);
121121
static Node *makeBoolAConst(bool state, int location);
122-
static FuncCall *makeOverlaps(List *largs, List *rargs,
123-
int location, core_yyscan_t yyscanner);
124122
static void check_qualified_name(List *names, core_yyscan_t yyscanner);
125123
static List *check_func_name(List *names, core_yyscan_t yyscanner);
126124
static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
@@ -10314,7 +10312,26 @@ a_expr: c_expr { $$ = $1; }
1031410312
}
1031510313
| row OVERLAPS row
1031610314
{
10317-
$$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
10315+
FuncCall *n = makeNode(FuncCall);
10316+
n->funcname = SystemFuncName("overlaps");
10317+
if (list_length($1) != 2)
10318+
ereport(ERROR,
10319+
(errcode(ERRCODE_SYNTAX_ERROR),
10320+
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10321+
parser_errposition(@1)));
10322+
if (list_length($3) != 2)
10323+
ereport(ERROR,
10324+
(errcode(ERRCODE_SYNTAX_ERROR),
10325+
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10326+
parser_errposition(@3)));
10327+
n->args = list_concat($1, $3);
10328+
n->agg_order = NIL;
10329+
n->agg_star = FALSE;
10330+
n->agg_distinct = FALSE;
10331+
n->func_variadic = FALSE;
10332+
n->over = NULL;
10333+
n->location = @2;
10334+
$$ = (Node *)n;
1031810335
}
1031910336
| a_expr IS TRUE_P %prec IS
1032010337
{
@@ -12889,39 +12906,6 @@ makeBoolAConst(bool state, int location)
1288912906
return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
1289012907
}
1289112908

12892-
/* makeOverlaps()
12893-
* Create and populate a FuncCall node to support the OVERLAPS operator.
12894-
*/
12895-
static FuncCall *
12896-
makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
12897-
{
12898-
FuncCall *n = makeNode(FuncCall);
12899-
12900-
n->funcname = SystemFuncName("overlaps");
12901-
if (list_length(largs) == 1)
12902-
largs = lappend(largs, largs);
12903-
else if (list_length(largs) != 2)
12904-
ereport(ERROR,
12905-
(errcode(ERRCODE_SYNTAX_ERROR),
12906-
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
12907-
parser_errposition(location)));
12908-
if (list_length(rargs) == 1)
12909-
rargs = lappend(rargs, rargs);
12910-
else if (list_length(rargs) != 2)
12911-
ereport(ERROR,
12912-
(errcode(ERRCODE_SYNTAX_ERROR),
12913-
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
12914-
parser_errposition(location)));
12915-
n->args = list_concat(largs, rargs);
12916-
n->agg_order = NIL;
12917-
n->agg_star = FALSE;
12918-
n->agg_distinct = FALSE;
12919-
n->func_variadic = FALSE;
12920-
n->over = NULL;
12921-
n->location = location;
12922-
return n;
12923-
}
12924-
1292512909
/* check_qualified_name --- check the result of qualified_name production
1292612910
*
1292712911
* It's easiest to let the grammar production for qualified_name allow

0 commit comments

Comments
 (0)