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 1lqehd-0001Uw-Ng for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Jun 2021 16:35:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lqehc-0004AR-N4 for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Jun 2021 16:35:44 +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 1lqehc-0004AJ-GJ for pgsql-bugs@lists.postgresql.org; Tue, 08 Jun 2021 16:35:44 +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 1lqehZ-0005ZB-D0 for pgsql-bugs@lists.postgresql.org; Tue, 08 Jun 2021 16:35:43 +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 158GZcHK1119341; Tue, 8 Jun 2021 12:35:38 -0400 From: Tom Lane To: "David G. Johnston" cc: Arthur McGibbon , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #17051: Incorrect params inferred on PREPARE In-reply-to: References: <17051-c20aad26366e11b4@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Tue, 08 Jun 2021 06:48:32 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1119339.1623170138.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 08 Jun 2021 12:35:38 -0400 Message-ID: <1119340.1623170138@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tuesday, June 8, 2021, Arthur McGibbon wr= ote: >> Could you point me to the documentation - I could only find >> https://www.postgresql.org/docs/current/sql-prepare.html and it doesn't >> mention how unknown params are handled. > https://www.postgresql.org/docs/current/typeconv-union-case.html Yeah, the point here is that the type of the parameter symbol is guessed in the context of resolving the CASE construct. There's no mechanism for applying external knowledge about what that CASE ought to yield. While maybe we could do something in this specific context, examples that are only slightly more complex would really be quite impossible. For example, ... SET timestampCol =3D foo(CASE WHEN timestampCol IS NULL THEN $1 ELSE N= ULL END); There's no way to tell which foo() function is meant until we've identified a result type for the CASE, so the function context is pretty much a blocker. Roughly speaking, we only get to use one syntactic level of context to guess the type of a parameter symbol. Doing better would really be a research project. regards, tom lane