From: Tom Lane <tgl@sss.pgh.pa.us>
To: Maciek Sakrejda <msakrejda@truviso.com>
Cc: Oliver Jowett <oliver@opencloud.com>
Cc: bht@actrix.gen.nz
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bug: Cannot pass null in Parameter in Query for ISNULL
Date: Thu, 01 Dec 2011 19:21:41 -0500
Message-ID: <19011.1322785301@sss.pgh.pa.us> (raw)
In-Reply-To: <CAH_hXRY2UEBZFAEHGohxz7OKLiwY5QxC2HbRPECsO4hM4cptNw@mail.gmail.com>
References: <6ekbd7dm4d6su5b9i4hsf92ibv4j76n51f@4ax.com>
<CA+0W9LN_HnO8AKPBTLAGWo9xfYnFXGT7BcCNBp7xBsx1y_y5-w@mail.gmail.com>
<CA+0W9LM4xcS0r=X_TwUA4kJKpat+1WitY01eB8WD6Rgzj=i0mg@mail.gmail.com>
<htlbd79p6n9uf8guddj3sg995i786ode99@4ax.com>
<CA+0W9LPMOW6pD7sMuvupDaFNvFowrE2trNuark2PTbCmyRVDvQ@mail.gmail.com>
<otbed755q4hd5fnevkpnetcf6csep0b97u@4ax.com>
<CA+0W9LM-MeO5V66MNLWEG0LJwTZmKhaa5_FiEU_pU9-V_Ae0yQ@mail.gmail.com>
<CAH_hXRY2UEBZFAEHGohxz7OKLiwY5QxC2HbRPECsO4hM4cptNw@mail.gmail.com>
Maciek Sakrejda <msakrejda@truviso.com> writes:
> I guess one possible way to do this would be to only inline null
> values when binding parameters, although that seems on the dangerous
> side of clever (and you'd have a hell of a time getting it to work
> with named prepared statements).
That seems unlikely to help much. Presumably, the OP isn't interested
in a constant-true result, so what he's really doing is hoping that
"$1 IS NULL" will report whether or not the passed parameter is null,
when sometimes it will be and sometimes it won't.
The difficulty from the server's point of view is really what data type
should be reported for the parameter symbol, if the client does a
Describe on the prepared statement. There is no context that would let
us guess what the application is thinking will happen. If we simply
removed the error checks about this, what would happen is that the
server would report "unknown" (yes, there is actually a type named
"unknown" in the Postgres system catalogs), and maybe the client-side
code would deal gracefully with that or maybe it wouldn't. If we try to
resolve the unknown to any specific ordinary type, we're likely to break
things even worse, if the application is expecting something different.
A lesser problem is that if we let the type stand as "unknown", the
existing server I/O functions take that as equivalent to "text".
Which means that if you send some binary data (perhaps because the
application thinks the parameter is integer), the server will most
likely spit up, because the data isn't a well-formed string in the
proper encoding. We could probably redefine things to avoid this
issue, but I'd be a bit worried about breakage.
In the end the nastiest issues are probably on the driver or interface
library. If it doesn't know what data type the parameter is supposed to
be, how is it going to go about forwarding a value to the server? Dumb
libraries like libpq may not have much of an issue here, but anything
with any intelligence is likely to be unhappy.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: tgl@sss.pgh.pa.us, msakrejda@truviso.com, oliver@opencloud.com, bht@actrix.gen.nz
Subject: Re: Bug: Cannot pass null in Parameter in Query for ISNULL
In-Reply-To: <19011.1322785301@sss.pgh.pa.us>
References: <6ekbd7dm4d6su5b9i4hsf92ibv4j76n51f@4ax.com> <CA+0W9LN_HnO8AKPBTLAGWo9xfYnFXGT7BcCNBp7xBsx1y_y5-w@mail.gmail.com> <CA+0W9LM4xcS0r=X_TwUA4kJKpat+1WitY01eB8WD6Rgzj=i0mg@mail.gmail.com> <htlbd79p6n9uf8guddj3sg995i786ode99@4ax.com> <CA+0W9LPMOW6pD7sMuvupDaFNvFowrE2trNuark2PTbCmyRVDvQ@mail.gmail.com> <otbed755q4hd5fnevkpnetcf6csep0b97u@4ax.com> <CA+0W9LM-MeO5V66MNLWEG0LJwTZmKhaa5_FiEU_pU9-V_Ae0yQ@mail.gmail.com> <CAH_hXRY2UEBZFAEHGohxz7OKLiwY5QxC2HbRPECsO4hM4cptNw@mail.gmail.com> <19011.1322785301@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox