Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u9mJZ-006DO4-LX for pgsql-general@arkaria.postgresql.org; Tue, 29 Apr 2025 14:52:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u9mJX-007pns-HR for pgsql-general@arkaria.postgresql.org; Tue, 29 Apr 2025 14:52:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u9mJX-007pnO-75 for pgsql-general@lists.postgresql.org; Tue, 29 Apr 2025 14:52:04 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u9mJW-000CRy-0A for pgsql-general@lists.postgresql.org; Tue, 29 Apr 2025 14:52:03 +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 53TEpwvp1026717; Tue, 29 Apr 2025 10:51:58 -0400 From: Tom Lane To: David Rowley cc: Tim Starling , pgsql-general@lists.postgresql.org Subject: Re: Upsert error "column reference is ambiguous" In-reply-to: References: <697017.1745837694@sss.pgh.pa.us> <80f95342-cc09-4236-a2d7-68538fbfc41b@wikimedia.org> <774865.1745848449@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Wed, 30 Apr 2025 00:43:17 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1026715.1745938318.1@sss.pgh.pa.us> Date: Tue, 29 Apr 2025 10:51:58 -0400 Message-ID: <1026716.1745938318@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > Another thought is that you can have an UPDATE with a RETURNING > clause. An unqualified column defaults to NEW even though you could > argue it's ambiguous due to OLD (as of 80feb727c). Likely we were > forced into making it work that way through not wanting to force > everyone to rewrite their RETURNING statements when upgrading to v18. > The moral of that story is, UPDATE isn't exactly consistent already > about when it requires column qualifications. Maybe it's weird to > insist that users qualify columns with their ON CONFLICT UPDATE SET > when RETURNING is happy to assume you must have meant NEW. That's an analogy I hadn't thought of, and it does seem on-point. You might be right that we would not have done it like that if we'd invented RETURNING's ability to support "OLD" at the get-go. Nonetheless, it's there now and is a pretty similar precedent. regards, tom lane