Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgtjY-0005nb-L2 for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Jul 2018 15:23:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fgtjT-0004Du-Vs for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Jul 2018 15:23:43 +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 1fgtjT-0004Dn-QJ for pgsql-bugs@lists.postgresql.org; Sat, 21 Jul 2018 15:23:43 +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 1fgtjQ-0007Zi-8H for pgsql-bugs@lists.postgresql.org; Sat, 21 Jul 2018 15:23:43 +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 w6LFNaFX003989; Sat, 21 Jul 2018 11:23:37 -0400 From: Tom Lane To: farmernick-pg@varteg.nz cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15289: Type inference of parameters in prepared statements can sometimes fail or succeed, depending... In-reply-to: <153217363212.1404.494341354166053594@wrigleys.postgresql.org> References: <153217363212.1404.494341354166053594@wrigleys.postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Sat, 21 Jul 2018 11:47:12 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3987.1532186616.1@sss.pgh.pa.us> Date: Sat, 21 Jul 2018 11:23:36 -0400 Message-ID: <3988.1532186616@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?utf-8?q?PG_Bug_reporting_form?= writes: > Type inference of parameters in prepared statements can sometimes fail even > though all the information is present and can be obtained if the statement > is altered in a way that really shouldn't make any functional difference. This is not a bug. If you don't specify a type for a parameter, the parser attempts to infer it on first use. If the first use is "v = $1", it will guess that $1 is meant to be the same type as v (whose type is already known from having processed the FROM clause). If the first use is "$1 IS NULL", there's no basis to infer a type. One could imagine some complicated parse-time processing that tries to defer resolving the parameter's type in hopes that some other use will be seen later; but there is no such thing in PG, and I doubt it will appear soon. regards, tom lane