Skip to content

Commit e1b8e0e

Browse files
committed
Disallow UNION/INTERSECT/EXCEPT over no columns.
Since 9.4, we've allowed the syntax "select union select" and variants of that. However, the planner wasn't expecting a no-column set operation and ended up treating the set operation as if it were UNION ALL. Pre-v10, there seem to be some executor issues that would need to be fixed to support such cases, and it doesn't really seem worth expending much effort on. Just disallow it, instead. Per report from Victor Yegorov. Discussion: https://postgr.es/m/CAGnEbojGJrRSOgJwNGM7JSJZpVAf8xXcVPbVrGdhbVEHZ-BUMw@mail.gmail.com
1 parent 02f66d8 commit e1b8e0e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/backend/optimizer/prep/prepunion.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,12 +592,13 @@ generate_nonunion_plan(SetOperationStmt *op, PlannerInfo *root,
592592
/* Identify the grouping semantics */
593593
groupList = generate_setop_grouplist(op, tlist);
594594

595-
/* punt if nothing to group on (can this happen?) */
595+
/* punt if nothing to group on (not worth fixing in back branches) */
596596
if (groupList == NIL)
597-
{
598-
*sortClauses = NIL;
599-
return plan;
600-
}
597+
ereport(ERROR,
598+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
599+
/* translator: %s is UNION, INTERSECT, or EXCEPT */
600+
errmsg("%s over no columns is not supported",
601+
(op->op == SETOP_INTERSECT) ? "INTERSECT" : "EXCEPT")));
601602

602603
/*
603604
* Estimate number of distinct groups that we'll need hashtable entries
@@ -736,12 +737,12 @@ make_union_unique(SetOperationStmt *op, Plan *plan,
736737
/* Identify the grouping semantics */
737738
groupList = generate_setop_grouplist(op, plan->targetlist);
738739

739-
/* punt if nothing to group on (can this happen?) */
740+
/* punt if nothing to group on (not worth fixing in back branches) */
740741
if (groupList == NIL)
741-
{
742-
*sortClauses = NIL;
743-
return plan;
744-
}
742+
ereport(ERROR,
743+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
744+
/* translator: %s is UNION, INTERSECT, or EXCEPT */
745+
errmsg("%s over no columns is not supported", "UNION")));
745746

746747
/*
747748
* XXX for the moment, take the number of distinct groups as equal to the

0 commit comments

Comments
 (0)