Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f1C6P-0004fE-R9 for pgsql-bugs@arkaria.postgresql.org; Wed, 28 Mar 2018 14:31:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f1C6O-0007Fj-5t for pgsql-bugs@arkaria.postgresql.org; Wed, 28 Mar 2018 14:31:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f1C6N-0007FZ-Vr for pgsql-bugs@lists.postgresql.org; Wed, 28 Mar 2018 14:31:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f1C6H-0006Su-7N for pgsql-bugs@postgresql.org; Wed, 28 Mar 2018 14:30:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w2SEUokf020458; Wed, 28 Mar 2018 10:30:50 -0400 From: Tom Lane To: =?UTF-8?Q?R=C3=A9mi_Aubel?= cc: pgsql-bugs@postgresql.org Subject: Re: BUG: Unable to bind a null value typed as a UUID in a PreparedStatement In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?R=C3=A9mi_Aubel?= message dated "Wed, 28 Mar 2018 13:26:48 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20456.1522247450.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 28 Mar 2018 10:30:50 -0400 Message-ID: <20457.1522247450@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?UTF-8?Q?R=3DC3=3DA9mi_Aubel?=3D writes: > I need to bind a UUID parameter which may be null in a statement like > "select * from test table where ? is null or ? =3D c_uuid". > Whatever approach I use, the driver rejects my request with "ERROR: coul= d > not determine data type of parameter $1". Some experimentation suggests that it'd probably work if you wrote the clauses in the other order: regression=3D# create table test_table (c_uuid uuid); CREATE TABLE regression=3D# prepare foo as select * from test_table where $1 is null or= $1 =3D c_uuid; ERROR: could not determine data type of parameter $1 LINE 1: prepare foo as select * from test_table where $1 is null or ... ^ regression=3D# prepare foo as select * from test_table where $1 =3D c_uuid= or $1 is null; PREPARE In an ideal world, perhaps the order of the parameter references would not matter, but AFAICS making that work would be mighty hard. For now, PG's parser wants to resolve the type of an otherwise-unlabeled parameter symbol the first time it sees it --- and the context "IS NULL" offers no clue what type it should be. Alternatively, you could force the issue with an explicit cast in the text of the query: regression=3D# prepare foo2 as select * from test_table where $1::uuid is = null or $1 =3D c_uuid; PREPARE regards, tom lane