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 1u9OYX-001JiU-VE for pgsql-general@arkaria.postgresql.org; Mon, 28 Apr 2025 13:29:58 +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 1u9OYV-000yPb-Va for pgsql-general@arkaria.postgresql.org; Mon, 28 Apr 2025 13:29:57 +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 1u9OYV-000yPS-KL for pgsql-general@lists.postgresql.org; Mon, 28 Apr 2025 13:29:56 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u9OYU-0000a7-2R for pgsql-general@lists.postgresql.org; Mon, 28 Apr 2025 13:29:56 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-39ee623fe64so4792873f8f.1 for ; Mon, 28 Apr 2025 06:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1745846992; x=1746451792; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=Y713/l2AdkWLOyEO5J4GTrJHpf3fArC2UWcPkAEQI+0=; b=rC6s9JGat5dS87qTCZ1Hec9U7F3JOnIC5lURGK4Nx2PhmDuJJnPMddHMQ5wTLLhZ8h aXxnVoAcCeEc3z8oNKJ7ylbYtUBK70or8S0mPG1WA1yBEq8Xu0T/nAybY3ezr72G67Oe 9BjYT5nXbw/0gap59/bV+NtaQQH6SW1IKQfRDy8CKaoTNwp3s4RJGp5iKeErL5Db5OgH Qb15LBpNr8C62Jhq9+aU57pLS55v3QbzYNJ/4wvhUbCUNMbHs0j4skuOnO4HiLkyl4qK k/kWo42S07IJGFDFA3gbnh9TRcEt2qJd8dsl2Slc2qcPMclZLfCTaZIrFlS6YD3H551K dIUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745846992; x=1746451792; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Y713/l2AdkWLOyEO5J4GTrJHpf3fArC2UWcPkAEQI+0=; b=M2m4yrgeW6Y+f5XGJ++qLK9d/mf4CfDBOFqtTklPcF6YGKBvPm45STvbUatLMW2ZiW ezGiGwiSzeSPqpGTpTEpEO9gPM0lMYNAodSy2yqVcnbplNEiAf7jq5xKFAKDTPM69nJz 01CtnuQ7+f5tXzpFXsnPxFWqol4O8KuGNj3o7DqzuRWY5jVVrpy2YoXgJZWFtqQBgCSw bhqrzmED9Nu7nIMhkInq2f+qj4vRljF6UStWmKx4mzDLaII0Qwu6UoTpSYvwyN6TnvZu SHB/iLcOsmcKfEuNbQ4wDI8SHwGZ32/3FfJ4yp/UKJXWwJletE+5JAF1w7TaEydBUTJa O1Fg== X-Gm-Message-State: AOJu0YxLCs9bY/LZgmBovhWVE/tM/9vSGLi7fz0h0G8B1/XAXsNAe5VX 32no4XcgaNiIOAp7df0q/vJWrFOT7KaZhZyiUmAbxq0QSpmvwXTXHynxSrZ80pE= X-Gm-Gg: ASbGncsyG8snX5cCJmel1c+IyKoxWnJs5zwIYdie9bJkzQDRXz4FtxbNZ79PJqhZucQ eMzQ3XcmSiAvR4Oc1cLNzHzgKtlh1TFSdxHKd0Dl7FemOw28tuq9Uw/q6sB9shWw6Kh8c3vbHfy OQr+RsXpXD6u5gtOPiAeK/kdr1epIx55kgzZDWrdrwjNkf2KCQRcvWmP6VRMHIX+KWuo2kq1sRb cXLfjAXJRCSLFyrEsrVHGojllYQ6n9BzT86KA4B28n2RIpiNpZnooO0iiV1yTzVPBNWh9bCTZXZ ixB4YtD7P4AsIxM/oAnLFOYLuJzRW32hITUSZIdrQUy5q1d+1xrEPzc68Q== X-Google-Smtp-Source: AGHT+IEWh/fWVbPWO+rlIocIOMKkaJB1sh1jvPNmmG86qDneA/muLkmEbqdfktpuSkNW7LROc6/iog== X-Received: by 2002:a05:6000:40ce:b0:39a:c80b:8283 with SMTP id ffacd0b85a97d-3a074e37a25mr10089108f8f.31.1745846992648; Mon, 28 Apr 2025 06:29:52 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:b56a:ce16:bfc1:eee:4d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4409d29b9c4sm160455745e9.3.2025.04.28.06.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 06:29:52 -0700 (PDT) Message-ID: Subject: Re: Upsert error "column reference is ambiguous" From: Laurenz Albe To: Tim Starling , Tom Lane Cc: pgsql-general@lists.postgresql.org Date: Mon, 28 Apr 2025 15:29:51 +0200 In-Reply-To: <80f95342-cc09-4236-a2d7-68538fbfc41b@wikimedia.org> References: <697017.1745837694@sss.pgh.pa.us> <80f95342-cc09-4236-a2d7-68538fbfc41b@wikimedia.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2025-04-28 at 21:22 +1000, Tim Starling wrote: > On 28/4/25 20:54, Tom Lane wrote: > > Even if I were on board with arbitrarily adopting one of the two > > possible interpretations, it's far from obvious to me that most people > > would agree that "v" should mean the value from the existing row, > > rather than the new value. Better to make them say which they want. >=20 > OK sure, no way to tell, but if every other DBMS does it the same way=20 > then that might be a hint. Which DBMS that supports INSERT .. ON CONFLICT do you have in mind? > Also, I'm just saying, the upsert feature is fully useless to me with=20 > this name resolution policy. Because you cannot write EXCLUDED? > In the single-row case, there's no need for EXCLUDED at all, because=20 > the client knows everything about the excluded row. Recall my example: >=20 > INSERT INTO t VALUES (1,1) ON CONFLICT (k) DO UPDATE SET v=3Dv+1; >=20 > If I meant SET v=3DEXCLUDED.v+1 I would have just written v=3D2. The=20 > default policy (in other DBMSes) follows by analogy from the=20 > single-row case. Actually, for many people, the DWIM would be the other way around: INSERT INTO tab (col) SELECT something FROM othertab ON CONFLICT (id) /* "col" should get set to "something" */ DO UPDATE SET col =3D col; I can follow your reasoning above, but if the SQL parser tried to guess the user's intention like that, it is likely to go wrong sometimes. As Tom said, better force the user to be explicit. Yours, Laurenz Albe