Re: BUG #19922: CYCLE/SEARCH with a window in the recursive term: could not find replacement targetlist entry

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nitin Motiani <nitinmotiani(at)google(dot)com>
Cc: tharakan(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: BUG #19922: CYCLE/SEARCH with a window in the recursive term: could not find replacement targetlist entry
Date: 2026-11-20 16:57:16
Message-ID: 1533786.1795193836@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Nitin Motiani <nitinmotiani(at)google(dot)com> writes:
> On Fri, Nov 20, 2026 at 3:17 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> I think the problem is that rewriteSearchAndCycle() is appending extra
>> items to the right subquery's tlist without regard for the possibility
>> that there are resjunk items in it.

> Thanks for the idea. I checked this and it indeed seemed to be the case.
> I'm attaching a patch with the fix in this area.

Thanks for doing the legwork. I pushed this after rewriting the
initial hunk a little: I didn't like just assuming that we know the
number of non-resjunk columns. rewriteTargetListIU() splits the
tlist using explicit checks on the resjunk flags, and I think this
code should do the same. We can assert that the result matches the
CTE column list afterwards.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Raja Sai pranav 2026-11-20 16:57:50 Re: BUG #19902: DECLARE CURSOR over trigger transition table fails with XX000
Previous Message Fujii Masao 2026-11-20 15:43:36 Re: BUG #19631: currtid2() on a view with GROUP BY ctid crashes with XX000