pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: coladict@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14268: NULL parameter conversion
Date: Thu, 28 Jul 2016 13:30:07 +0000
Message-ID: <20160728133007.1423.60398@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      14268
Logged by:          Jordan Gigov
Email address:      coladict@gmail.com
PostgreSQL version: 9.3.13
Operating system:   Ubuntu 14.04
Description:        

When setting a parameter in a prepared statement to NULL through JDBC (the
problem is not there, I went through that code), if the parameter type (or
Oid as it seems to be called in your code) is different, than the column
type it causes a typecasting error. When the value is NULL, the type
shouldn't matter.

There is no standard way to explicitly specify the type when setting a
parameter to null in Java Persistence API, thus the only other way to avoid
the error would be to have a complete analysis of the query and metamodel
before sending it to the database.

The JPA provider I'm using explicitly skips PostgreSQL in it's tests for
NULL parameters in prepared statements, and no other database.

A console example of how to trigger the error:

CREATE TABLE my_array_table(id serial NOT NULL, somedata bigint[], PRIMARY
KEY(id));
INSERT INTO my_array_table(somedata) VALUES (NULL);
INSERT INTO my_array_table(somedata) VALUES (NULL::integer[]);
INSERT INTO my_array_table(somedata) VALUES (NULL::bytea);

I recognize that the JDBC driver explicitly sends the parameter type in a
prepared statement, but I think it should be ignored when the value is
NULL.

As best I can tell, the place for that check is in
backend/parser/parse_coerce.c -> coerce_to_target_type() before or along
with the call to can_coerce_type().
But I'm out of practice with C, and not deep enough in your project to say
there isn't a better solution.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (8+ messages)  latest in thread

Message-ID: <20160728133007.1423.60398@wrigleys.postgresql.org>
Permalink:  ../20160728133007.1423.60398@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160728133007.1423.60398@wrigleys.postgresql.org

 · 

reply

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-bugs@postgresql.org
  Cc: coladict@gmail.com
  Subject: Re: BUG #14268: NULL parameter conversion
  In-Reply-To: <20160728133007.1423.60398@wrigleys.postgresql.org>
  References: <20160728133007.1423.60398@wrigleys.postgresql.org>

* 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