Skip to content

Commit bd29bc4

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 23b6341 commit bd29bc4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/optimizer/prep/prepunion.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,13 @@ generate_nonunion_path(SetOperationStmt *op, PlannerInfo *root,
697697
/* Identify the grouping semantics */
698698
groupList = generate_setop_grouplist(op, tlist);
699699

700-
/* punt if nothing to group on (can this happen?) */
700+
/* punt if nothing to group on (not worth fixing in back branches) */
701701
if (groupList == NIL)
702-
return path;
702+
ereport(ERROR,
703+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
704+
/* translator: %s is UNION, INTERSECT, or EXCEPT */
705+
errmsg("%s over no columns is not supported",
706+
(op->op == SETOP_INTERSECT) ? "INTERSECT" : "EXCEPT")));
703707

704708
/*
705709
* Estimate number of distinct groups that we'll need hashtable entries
@@ -850,9 +854,12 @@ make_union_unique(SetOperationStmt *op, Path *path, List *tlist,
850854
/* Identify the grouping semantics */
851855
groupList = generate_setop_grouplist(op, tlist);
852856

853-
/* punt if nothing to group on (can this happen?) */
857+
/* punt if nothing to group on (not worth fixing in back branches) */
854858
if (groupList == NIL)
855-
return path;
859+
ereport(ERROR,
860+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
861+
/* translator: %s is UNION, INTERSECT, or EXCEPT */
862+
errmsg("%s over no columns is not supported", "UNION")));
856863

857864
/*
858865
* XXX for the moment, take the number of distinct groups as equal to the

0 commit comments

Comments
 (0)