BUG #14268: NULL parameter conversion

From: coladict(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14268: NULL parameter conversion
Date: 2016-07-28 13:30:07
Message-ID: 20160728133007.1423.60398@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14268
Logged by: Jordan Gigov
Email address: coladict(at)gmail(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2016-07-28 13:56:34 Re: BUG #14268: NULL parameter conversion
Previous Message Michael Paquier 2016-07-28 05:22:29 Re: BUG #14228: replication slot catalog_xmin not cleared on slot reuse