aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-12-02 20:28:56 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-12-02 20:28:56 -0500
commitf67b8aeab3a543d156787de7311d4a98f228ab9f (patch)
tree0803ca71bdb2eada23e0648b602d2e74ad30e26e
parentc53cbb39f880959d7ca04f43943e787ec5cad830 (diff)
downloadpostgresql-f67b8aeab3a543d156787de7311d4a98f228ab9f.tar.gz
postgresql-f67b8aeab3a543d156787de7311d4a98f228ab9f.zip
Fix crash in assign_collations_walker for EXISTS with empty SELECT list.
We (I think I, actually) forgot about this corner case while coding collation resolution. Per bug #8648 from Arjen Nienhuis.
-rw-r--r--src/backend/parser/parse_collate.c10
-rw-r--r--src/test/regress/expected/subselect.out10
-rw-r--r--src/test/regress/sql/subselect.sql6
3 files changed, 24 insertions, 2 deletions
diff --git a/src/backend/parser/parse_collate.c b/src/backend/parser/parse_collate.c
index f0cd3f88d23..ec606ebcac7 100644
--- a/src/backend/parser/parse_collate.c
+++ b/src/backend/parser/parse_collate.c
@@ -564,16 +564,22 @@ assign_collations_walker(Node *node, assign_collations_context *context)
* SubLink. Act as though the Query returns its first output
* column, which indeed is what it does for EXPR_SUBLINK and
* ARRAY_SUBLINK cases. In the cases where the SubLink
- * returns boolean, this info will be ignored.
+ * returns boolean, this info will be ignored. Special case:
+ * in EXISTS, the Query might return no columns, in which case
+ * we need do nothing.
*
* We needn't recurse, since the Query is already processed.
*/
Query *qtree = (Query *) node;
TargetEntry *tent;
+ if (qtree->targetList == NIL)
+ return false;
tent = (TargetEntry *) linitial(qtree->targetList);
Assert(IsA(tent, TargetEntry));
- Assert(!tent->resjunk);
+ if (tent->resjunk)
+ return false;
+
collation = exprCollation((Node *) tent->expr);
/* collation doesn't change if it's converted to array */
strength = COLLATE_IMPLICIT;
diff --git a/src/test/regress/expected/subselect.out b/src/test/regress/expected/subselect.out
index 3f33efd7001..d5c6a7eb213 100644
--- a/src/test/regress/expected/subselect.out
+++ b/src/test/regress/expected/subselect.out
@@ -703,3 +703,13 @@ explain (verbose, costs off)
One-Time Filter: ("*VALUES*".column1 = "*VALUES*".column1)
(8 rows)
+--
+-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
+--
+create temp table nocolumns();
+select exists(select * from nocolumns);
+ ?column?
+----------
+ f
+(1 row)
+
diff --git a/src/test/regress/sql/subselect.sql b/src/test/regress/sql/subselect.sql
index 0795d435346..278580797ec 100644
--- a/src/test/regress/sql/subselect.sql
+++ b/src/test/regress/sql/subselect.sql
@@ -405,3 +405,9 @@ explain (verbose, costs off)
explain (verbose, costs off)
select x, x from
(select (select random() where y=y) as x from (values(1),(2)) v(y)) ss;
+
+--
+-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
+--
+create temp table nocolumns();
+select exists(select * from nocolumns);