Re: BUG #15289: Type inference of parameters in prepared statements can sometimes fail or succeed, depending... - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #15289: Type inference of parameters in prepared statements can sometimes fail or succeed, depending...
Date
Msg-id 3988.1532186616@sss.pgh.pa.us
Whole thread Raw
In response to BUG #15289: Type inference of parameters in prepared statements cansometimes fail or succeed, depending...  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> 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


pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #15289: Type inference of parameters in prepared statements cansometimes fail or succeed, depending...
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #15289: Type inference of parameters in prepared statementscan sometimes fail or succeed, depending...