Remove broken code that tried to handle OVERLAPS with a single argument.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Feb 2014 17:44:20 +0000 (12:44 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Feb 2014 17:44:20 +0000 (12:44 -0500)
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.

src/backend/parser/gram.y

index ab3538a4afafaa863d00361058ab97c87e04274a..81169a4896d71f29abd286c548aa67095af2a412 100644 (file)
@@ -136,8 +136,6 @@ static Node *makeBitStringConst(char *str, int location);
 static Node *makeNullAConst(int location);
 static Node *makeAConst(Value *v, int location);
 static Node *makeBoolAConst(bool state, int location);
-static FuncCall *makeOverlaps(List *largs, List *rargs,
-                             int location, core_yyscan_t yyscanner);
 static void check_qualified_name(List *names, core_yyscan_t yyscanner);
 static List *check_func_name(List *names, core_yyscan_t yyscanner);
 static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
@@ -10949,7 +10947,19 @@ a_expr:        c_expr                                  { $$ = $1; }
                }
            | row OVERLAPS row
                {
-                   $$ = (Node *)makeOverlaps($1, $3, @2, yyscanner);
+                   if (list_length($1) != 2)
+                       ereport(ERROR,
+                               (errcode(ERRCODE_SYNTAX_ERROR),
+                                errmsg("wrong number of parameters on left side of OVERLAPS expression"),
+                                parser_errposition(@1)));
+                   if (list_length($3) != 2)
+                       ereport(ERROR,
+                               (errcode(ERRCODE_SYNTAX_ERROR),
+                                errmsg("wrong number of parameters on right side of OVERLAPS expression"),
+                                parser_errposition(@3)));
+                   $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
+                                              list_concat($1, $3),
+                                              @2);
                }
            | a_expr IS TRUE_P                          %prec IS
                {
@@ -13397,31 +13407,6 @@ makeBoolAConst(bool state, int location)
    return makeTypeCast((Node *)n, SystemTypeName("bool"), -1);
 }
 
-/* makeOverlaps()
- * Create and populate a FuncCall node to support the OVERLAPS operator.
- */
-static FuncCall *
-makeOverlaps(List *largs, List *rargs, int location, core_yyscan_t yyscanner)
-{
-   FuncCall *n;
-   if (list_length(largs) == 1)
-       largs = lappend(largs, largs);
-   else if (list_length(largs) != 2)
-       ereport(ERROR,
-               (errcode(ERRCODE_SYNTAX_ERROR),
-                errmsg("wrong number of parameters on left side of OVERLAPS expression"),
-                parser_errposition(location)));
-   if (list_length(rargs) == 1)
-       rargs = lappend(rargs, rargs);
-   else if (list_length(rargs) != 2)
-       ereport(ERROR,
-               (errcode(ERRCODE_SYNTAX_ERROR),
-                errmsg("wrong number of parameters on right side of OVERLAPS expression"),
-                parser_errposition(location)));
-   n = makeFuncCall(SystemFuncName("overlaps"), list_concat(largs, rargs), location);
-   return n;
-}
-
 /* check_qualified_name --- check the result of qualified_name production
  *
  * It's easiest to let the grammar production for qualified_name allow