Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfpZz-0000iF-V4 for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Sep 2016 14:36:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bfpZz-00073T-He for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Sep 2016 14:36:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bfpYc-00058W-Ad for pgsql-hackers@postgresql.org; Fri, 02 Sep 2016 14:35:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bfpYY-0002Bo-LF for pgsql-hackers@postgresql.org; Fri, 02 Sep 2016 14:35:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u82EYsKh010499; Fri, 2 Sep 2016 10:34:54 -0400 From: Tom Lane To: Andres Freund cc: Kevin Grittner , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: Implement targetlist SRFs using ROWS FROM() (was Changed SRF in targetlist handling) In-reply-to: <20160902142516.4oarwuvqoanyoezx@alap3.anarazel.de> References: <20160523005327.v2tr7obytitxcnna@alap3.anarazel.de> <20160822214023.aaxz5l4igypowyri@alap3.anarazel.de> <20160902141110.6xciuntt5h4i6eni@alap3.anarazel.de> <9965.1472826042@sss.pgh.pa.us> <20160902142516.4oarwuvqoanyoezx@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 02 Sep 2016 07:25:16 -0700" Date: Fri, 02 Sep 2016 10:34:54 -0400 Message-ID: <10498.1472826894@sss.pgh.pa.us> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andres Freund writes: > On 2016-09-02 10:20:42 -0400, Tom Lane wrote: >> ... ISTM all we >> need is that the SRF be on the inside of the join, which is automatic >> if it's LATERAL. > Right. But there's nothing to force a lateral reference to be there > intrinsically. I've added a "fake" lateral reference to the ROWS FROM > RTE to the subquery, when there's none otherwise, but that's not > entirely pretty. Hm, do you get cases like this right: select generate_series(1, t1.a) from t1, t2; That would result in a lateral ref from the SRF RTE to t1, but you really need to treat it as laterally dependent on the join of t1/t2 in order to preserve the old semantics. That is, you need to be laterally dependent on the whole FROM clause regardless of which variable references appear. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers