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 1sds0I-001jZC-M0 for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2024 13:56:02 +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 1sds0G-00467D-6I for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2024 13:56:00 +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 1sds0F-004675-R1 for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2024 13:55:59 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sds0D-004evG-Rt for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2024 13:55:59 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-53212e0aa92so1551879e87.0 for ; Tue, 13 Aug 2024 06:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723557356; x=1724162156; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FV5f14AVitMZaCmcdABF83oAm7rE8SgI+c3eqCgKcc8=; b=ACzN7LWIKS8Tq0Yui9WvkyzMZhRf1FYUIl0PFdK5aggPFaiv4uSi/w96+DhB3VFwCo M7i9idgDLGorL1biUF+/QAFKTlPZb3aZYAQMvJNoqWpS17fLDXY7fzNN0mzjpHV8ARw8 6QDPQSt6jgpJQLHvQ2iHGAuLwU9e87Jkn1WTLEWWo5kNvGIzaN7Lqq8zyHsICdUzXfJf 0QuBoALd08zeQBk9+CoVQpFybv2qla1H/x57r0JqvebfyE5QVBaHRlSdsDtStAXM4J3n DnHgucw6L81MZGOaQf4OvDFIUgzDDwS7WjZcH0c9YV8wUOsOp171TWN5bz84ExuJVMPr hXAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723557356; x=1724162156; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FV5f14AVitMZaCmcdABF83oAm7rE8SgI+c3eqCgKcc8=; b=OY7iamZfEoCgqZ6em3nmyCjlRabxZ4z/kD7AyAXk+Ay2CZl7IHckD3GAJCUGLWUMVY 9XWCmaL9kBzOc8EHglyg77WoWeVPkyB7Wm7o7NrMI7XQFJ265H5jL4F7uxDXVpgg68ek qKv1IAvhT4A9Ye+lOWEbSSyn/Tf0pwMq8AUGJsquEHf5A7qyuB/SL7jMocmyLljPiOOr N4/JhwKlBpx1NJXovEbGGNY0mdps5vhV7Dkm8KhWEyMWxwIULZg3eykVSFuT7ENJsECa wNJ1gkmhUZcwEyaG9msmWbvkwbtL7eDjI8aIfc4NS6wceJw2lhMsjjwLg19lHyey8+Yu CX7w== X-Forwarded-Encrypted: i=1; AJvYcCUWAUNkaRyHnYQREKEx1rt+68x7UygpLq9MG2FPHUvOEHXE0m0bUoiEhj/JAL8acU/LXW95nMwowqHbBoui9WzKe6zr0LvfUC9QD1uhsJ8nF1cg X-Gm-Message-State: AOJu0YxIBwYwmHLcotbvTzyo7QGRJSxRplzhvW523KMif7e/TTwRAJ+r nVk/gPaQNxJBP6OlmLT8R6rc4HtRLO5GNgyo8nMTLSdRZnxn43XF21zM9hc6jUqYbut3tJfW6d4 ZV63Q4T53XYgSfoauTmqzL0MIv4Q= X-Google-Smtp-Source: AGHT+IGUvh9xENDuaPsPWB8GQ2D+bjcGmUinjmbZ/Hzkdki130ENW4A0V2WSPDkeranoKQKimKf2C2SRm6kO/7Xc2iw= X-Received: by 2002:a05:6512:3049:b0:52c:952a:67da with SMTP id 2adb3069b0e04-532136a4728mr2583513e87.55.1723557355357; Tue, 13 Aug 2024 06:55:55 -0700 (PDT) MIME-Version: 1.0 References: <37e09717-f121-4192-b152-18df17713414@aklaver.com> <9dc702ca-8bb3-442e-bd2b-12abe81a84d0@aklaver.com> In-Reply-To: From: Greg Sabino Mullane Date: Tue, 13 Aug 2024 09:55:18 -0400 Message-ID: Subject: Re: Insert works but fails for merge To: Adrian Klaver Cc: Alban Hertroys , yudhi s , David G Johnston , pgsql-general Content-Type: multipart/alternative; boundary="000000000000ea8d98061f90f760" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ea8d98061f90f760 Content-Type: text/plain; charset="UTF-8" I just remembered that one of the complaints was not wanting to worry about looking up the data types. In my previous example, you can also leave out the types and Postgres will do the right thing. I prefer the explicit data type version for clarity, but though I would provide this one for completeness: prepare foo as with x as (update tab1 set mid=$2 where id=$1 returning 1) insert into tab1 select $1,$2,$3 where not exists (select 1 from x); Cheers, Greg --000000000000ea8d98061f90f760 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I just remembered that one of the complaints was not = wanting to worry about looking up the data types. In my previous example, y= ou can also leave out the types and Postgres will do the right thing. I pre= fer the explicit data type version for clarity, but though I would provide = this one for completeness:

<= div>prepare foo as with x as (update tab1 set mid=3D$2 where id=3D$1 return= ing 1)
=C2=A0 insert into tab1 select $1,$2,$3 where not exists (= select 1 from x);

Cheers,
Greg

--000000000000ea8d98061f90f760--