Re: BUG #17051: Incorrect params inferred on PREPARE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Arthur McGibbon <arthur(dot)mcgibbon(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17051: Incorrect params inferred on PREPARE
Date: 2021-06-08 16:35:38
Message-ID: 1119340.1623170138@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Tuesday, June 8, 2021, Arthur McGibbon <arthur(dot)mcgibbon(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-06-08 16:39:31 Re: BUG #17052: Incorrect params inferred on PREPARE (part 2)
Previous Message David G. Johnston 2021-06-08 13:48:32 Re: BUG #17051: Incorrect params inferred on PREPARE