Re: pg18 bug? SELECT query doesn't work

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eric Ridge <eebbrr(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>, Richard Guo <guofenglinux(at)gmail(dot)com>
Subject: Re: pg18 bug? SELECT query doesn't work
Date: 2026-01-06 18:52:12
Message-ID: 1607957.1767725532@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Eric Ridge <eebbrr(at)gmail(dot)com> writes:
> Here's an even more reduced test case. No tables or data:

> # SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as animal FROM generate_series(1, 10) GROUP BY 1) x WHERE animal ilike 'c%';

> pg15 returns:

> animal
> --------
> CAT
> (1 row)

> and pg18 says:

> # SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as animal FROM generate_series(1, 10) GROUP BY 1) x WHERE animal ilike 'c%';
> ERROR: set-valued function called in context that cannot accept a set
> LINE 1: SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as ...
> ^

I agree that this is a bug. "git bisect" says it broke at

247dea89f7616fdf06b7272b74abafc29e8e5860 is the first bad commit
commit 247dea89f7616fdf06b7272b74abafc29e8e5860 (HEAD)
Author: Richard Guo <rguo(at)postgresql(dot)org>
Date: Tue Sep 10 12:35:34 2024 +0900

Introduce an RTE for the grouping step

I've not probed further than that, but my guess is that now we check
for set-returning tlist items while the tlist still has grouping Vars,
thus missing the fact that there's a SRF represented by one of those
Vars. This prompts us to flatten a subquery we shouldn't have
flattened (because that ends by introducing a SRF into the outer
WHERE).

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric Ridge 2026-01-06 19:25:07 Re: pg18 bug? SELECT query doesn't work
Previous Message Eric Ridge 2026-01-06 18:28:27 Re: pg18 bug? SELECT query doesn't work

Browse pgsql-hackers by date

  From Date Subject
Next Message Marcos Pegoraro 2026-01-06 18:53:49 [PATCH] Change "the empty string" to "an empty string" on DOCs
Previous Message Peter Geoghegan 2026-01-06 18:47:53 Re: New year, new commitfest app improvements