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 1ohzmI-0005tB-ED for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Oct 2022 20:53:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ohzmH-0007BD-Ak for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Oct 2022 20:53:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ohzmH-0007B4-2i for pgsql-bugs@lists.postgresql.org; Mon, 10 Oct 2022 20:53:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ohzmE-0001Oe-OV for pgsql-bugs@lists.postgresql.org; Mon, 10 Oct 2022 20:53:32 +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 29AKrSfw151680; Mon, 10 Oct 2022 16:53:28 -0400 From: Tom Lane To: arthur.mcgibbon@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17631: Prepare + Merge fails to identify parameter types In-reply-to: <17631-7f892d95b3264da3@postgresql.org> References: <17631-7f892d95b3264da3@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 10 Oct 2022 17:14:34 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <151678.1665435208.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 10 Oct 2022 16:53:28 -0400 Message-ID: <151679.1665435208@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > create table foo (id int, bar bit); > PREPARE foo_merge as > merge into foo as target > using(values($1, $2)) > as source (id, bar) > on target.id =3D source.id > when matched then > update set bar =3D source.bar > when not matched then > insert(id, bar) > values ($1, $2); > gives error... > ERROR: operator does not exist: integer =3D text > LINE 5: on target.id =3D source.id > ^ > HINT: No operator matches the given name and argument types. You might = need > to add explicit type casts. I don't see any bug here. There's no reason to assume that the VALUES clause in USING must yield the same columns that the merge target table has, so those Params just default to text type. I realize that there are some kluges that let "insert into foo values($1,$2)" act differently, but the key word there is "kluge". VALUES in contexts other than INSERT has never had such a behavior. For example, if you do this: prepare foo as select * from foo join (values($1,$2)) v(f1,f2) on id =3D v= .f1; you'll get the very same failure: ERROR: operator does not exist: integer =3D text LINE 1: ...elect * from foo join (values($1,$2)) v(f1,f2) on id =3D v.f1; ^ HINT: No operator matches the given name and argument types. You might ne= ed to add explicit type casts. regards, tom lane