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 1lVAqe-0005fw-Fy for pgsql-bugs@arkaria.postgresql.org; Sat, 10 Apr 2021 10:28:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lVAqb-0006PK-Qr for pgsql-bugs@arkaria.postgresql.org; Sat, 10 Apr 2021 10:28:13 +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 1lVAqb-0006PC-Kr for pgsql-bugs@lists.postgresql.org; Sat, 10 Apr 2021 10:28:13 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVAqY-00017v-D7 for pgsql-bugs@lists.postgresql.org; Sat, 10 Apr 2021 10:28:12 +0000 X-Originating-IP: 79.88.149.14 Received: from [172.16.255.146] (14.149.88.79.rev.sfr.net [79.88.149.14]) (Authenticated sender: vik@postgresfriends.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id ED7181BF203; Sat, 10 Apr 2021 10:28:05 +0000 (UTC) Subject: Re: BUG #16958: "Invalid reference to FROM-clause entry for table" when qualifying columns in "on conflict .. where" To: Pantelis Theodosiou , Lukas Eder , pgsql-bugs@lists.postgresql.org References: <16958-963f638020de271c@postgresql.org> From: Vik Fearing Message-ID: <8a396e1e-c2a0-5ba3-180e-697082ae397f@postgresfriends.org> Date: Sat, 10 Apr 2021 12:28:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/10/21 9:57 AM, Pantelis Theodosiou wrote: > On Fri, Apr 9, 2021 at 11:00 PM PG Bug reporting form < > noreply@postgresql.org> wrote: > >> insert into t (a, b) >> values ( >> 1, >> 1 >> ) >> on conflict (a) >> where t.b is null -- Error here >> do update >> set >> c = 1 >> returning t.a, t.b, t.c; >> There's an error reported: >> >> SQL Error [42P01]: ERROR: invalid reference to FROM-clause entry for table >> "t" >> Hint: There is an entry for table "t", but it cannot be referenced from >> this part of the query. >> Position: 71 >> >> Notice the qualification of the t.b column in the "on conflict .. where" >> clause. I don't understand why b cannot be qualified at this location. It >> can be qualified in the index definition, looks like a bug to me. >> > > You don't need and shouldn't prefix the column with the table name in that > part. This should work: > > ... > on conflict (a) > where b is null > do update > ... Not needing to and not being able to are two completely different things. I believe tablename qualification should be allowed here even if it isn't necessary. -- Vik Fearing