Skip to content

Commit dd378dd

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 a9c43b1 commit dd378dd

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

src/backend/parser/gram.y

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +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, int location);
123122
static void check_qualified_name(List *names);
124123
static List *check_func_name(List *names);
125124
static List *check_indirection(List *indirection);
@@ -8393,7 +8392,25 @@ a_expr: c_expr { $$ = $1; }
83938392
}
83948393
| row OVERLAPS row
83958394
{
8396-
$$ = (Node *)makeOverlaps($1, $3, @2);
8395+
FuncCall *n = makeNode(FuncCall);
8396+
n->funcname = SystemFuncName("overlaps");
8397+
if (list_length($1) != 2)
8398+
ereport(ERROR,
8399+
(errcode(ERRCODE_SYNTAX_ERROR),
8400+
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
8401+
scanner_errposition(@1)));
8402+
if (list_length($3) != 2)
8403+
ereport(ERROR,
8404+
(errcode(ERRCODE_SYNTAX_ERROR),
8405+
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
8406+
scanner_errposition(@3)));
8407+
n->args = list_concat($1, $3);
8408+
n->agg_star = FALSE;
8409+
n->agg_distinct = FALSE;
8410+
n->func_variadic = FALSE;
8411+
n->over = NULL;
8412+
n->location = @2;
8413+
$$ = (Node *)n;
83978414
}
83988415
| a_expr IS TRUE_P
83998416
{
@@ -10762,38 +10779,6 @@ makeBoolAConst(bool state, int location)
1076210779
return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
1076310780
}
1076410781

10765-
/* makeOverlaps()
10766-
* Create and populate a FuncCall node to support the OVERLAPS operator.
10767-
*/
10768-
static FuncCall *
10769-
makeOverlaps(List *largs, List *rargs, int location)
10770-
{
10771-
FuncCall *n = makeNode(FuncCall);
10772-
10773-
n->funcname = SystemFuncName("overlaps");
10774-
if (list_length(largs) == 1)
10775-
largs = lappend(largs, largs);
10776-
else if (list_length(largs) != 2)
10777-
ereport(ERROR,
10778-
(errcode(ERRCODE_SYNTAX_ERROR),
10779-
errmsg("wrong number of parameters on left side of OVERLAPS expression"),
10780-
scanner_errposition(location)));
10781-
if (list_length(rargs) == 1)
10782-
rargs = lappend(rargs, rargs);
10783-
else if (list_length(rargs) != 2)
10784-
ereport(ERROR,
10785-
(errcode(ERRCODE_SYNTAX_ERROR),
10786-
errmsg("wrong number of parameters on right side of OVERLAPS expression"),
10787-
scanner_errposition(location)));
10788-
n->args = list_concat(largs, rargs);
10789-
n->agg_star = FALSE;
10790-
n->agg_distinct = FALSE;
10791-
n->func_variadic = FALSE;
10792-
n->over = NULL;
10793-
n->location = location;
10794-
return n;
10795-
}
10796-
1079710782
/* check_qualified_name --- check the result of qualified_name production
1079810783
*
1079910784
* 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