Re: DELETE ... USING LATERAL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nikhil Benesch <nikhil(dot)benesch(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: DELETE ... USING LATERAL
Date: 2021-10-04 17:48:39
Message-ID: 3998065.1633369719@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nikhil Benesch <nikhil(dot)benesch(at)gmail(dot)com> writes:
> Is it intentional that LATERAL elements in a USING clause of a DELETE
> statement can't reference the table declared in the FROM clause?

Hmm ... doesn't work for UPDATE, either.

My mental model of these things is that the target table is cross-joined
to the additional tables as though by a comma in FROM, so that what
you have here ought to work much like

select * from int_arrays, jsonb_array_each(int_array) _ (val)
where val::integer > 1;

Clearly it's not doing so as far as the LATERAL scoping is concerned.
Maybe we are adding the target table to the query after the additional
tables, not before them?

Not sure I'd call this a bug exactly, but maybe there's room for
improvement. Or maybe there is an actual semantic issue that
I'm not seeing right away.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nikhil Benesch 2021-10-04 18:36:16 Re: DELETE ... USING LATERAL
Previous Message Israel Brewster 2021-10-04 17:36:32 Re: Growth planning