Skip to content

Commit 7ab3214

Browse files
committed
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.
1 parent 02bb4bb commit 7ab3214

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/backend/parser/parse_collate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,22 @@ assign_collations_walker(Node *node, assign_collations_context *context)
484484
* SubLink. Act as though the Query returns its first output
485485
* column, which indeed is what it does for EXPR_SUBLINK and
486486
* ARRAY_SUBLINK cases. In the cases where the SubLink
487-
* returns boolean, this info will be ignored.
487+
* returns boolean, this info will be ignored. Special case:
488+
* in EXISTS, the Query might return no columns, in which case
489+
* we need do nothing.
488490
*
489491
* We needn't recurse, since the Query is already processed.
490492
*/
491493
Query *qtree = (Query *) node;
492494
TargetEntry *tent;
493495

496+
if (qtree->targetList == NIL)
497+
return false;
494498
tent = (TargetEntry *) linitial(qtree->targetList);
495499
Assert(IsA(tent, TargetEntry));
496-
Assert(!tent->resjunk);
500+
if (tent->resjunk)
501+
return false;
502+
497503
collation = exprCollation((Node *) tent->expr);
498504
/* collation doesn't change if it's converted to array */
499505
strength = COLLATE_IMPLICIT;

src/test/regress/expected/subselect.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,13 @@ explain (verbose, costs off)
700700
One-Time Filter: ("*VALUES*".column1 = "*VALUES*".column1)
701701
(8 rows)
702702

703+
--
704+
-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
705+
--
706+
create temp table nocolumns();
707+
select exists(select * from nocolumns);
708+
exists
709+
--------
710+
f
711+
(1 row)
712+

src/test/regress/sql/subselect.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,9 @@ explain (verbose, costs off)
405405
explain (verbose, costs off)
406406
select x, x from
407407
(select (select random() where y=y) as x from (values(1),(2)) v(y)) ss;
408+
409+
--
410+
-- Check we behave sanely in corner case of empty SELECT list (bug #8648)
411+
--
412+
create temp table nocolumns();
413+
select exists(select * from nocolumns);

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