Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXS4y-00030O-Pt for pgsql-general@arkaria.postgresql.org; Mon, 04 Oct 2021 17:48:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mXS4x-0007lD-Ot for pgsql-general@arkaria.postgresql.org; Mon, 04 Oct 2021 17:48:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXS4x-0007l5-Fk for pgsql-general@lists.postgresql.org; Mon, 04 Oct 2021 17:48:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXS4v-0001oe-JF for pgsql-general@lists.postgresql.org; Mon, 04 Oct 2021 17:48:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 194HmdOs3998066; Mon, 4 Oct 2021 13:48:40 -0400 From: Tom Lane To: Nikhil Benesch cc: "pgsql-generallists.postgresql.org" Subject: Re: DELETE ... USING LATERAL In-reply-to: References: Comments: In-reply-to Nikhil Benesch message dated "Mon, 04 Oct 2021 12:29:36 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3998064.1633369719.1@sss.pgh.pa.us> Date: Mon, 04 Oct 2021 13:48:39 -0400 Message-ID: <3998065.1633369719@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nikhil Benesch 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