Re: BUG #17051: Incorrect params inferred on PREPARE - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #17051: Incorrect params inferred on PREPARE
Date
Msg-id 1119340.1623170138@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #17051: Incorrect params inferred on PREPARE  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tuesday, June 8, 2021, Arthur McGibbon <arthur.mcgibbon@gmail.com> wrote:
>> 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 = foo(CASE WHEN timestampCol IS NULL THEN $1 ELSE NULL 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



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #17051: Incorrect params inferred on PREPARE
Next
From: Tom Lane
Date:
Subject: Re: BUG #17052: Incorrect params inferred on PREPARE (part 2)