From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nikhil Benesch <nikhil.benesch@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: DELETE ... USING LATERAL
Date: Mon, 04 Oct 2021 13:48:39 -0400
Message-ID: <3998065.1633369719@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPWqQZQQWDX2A4zzEyJ_rqks0zCOaC2r2yjN4bAcEVhKb0V5AQ@mail.gmail.com>
References: <CAPWqQZQQWDX2A4zzEyJ_rqks0zCOaC2r2yjN4bAcEVhKb0V5AQ@mail.gmail.com>
Nikhil Benesch <nikhil.benesch@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, nikhil.benesch@gmail.com
Subject: Re: DELETE ... USING LATERAL
In-Reply-To: <3998065.1633369719@sss.pgh.pa.us>
References: <CAPWqQZQQWDX2A4zzEyJ_rqks0zCOaC2r2yjN4bAcEVhKb0V5AQ@mail.gmail.com> <3998065.1633369719@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox