Bug: SimpleParameterList and resolved types

From: Bruno De Fraine <bruno(at)defraine(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Bug: SimpleParameterList and resolved types
Date: 2010-05-07 12:15:05
Message-ID: 8B9C0191-CBBB-497B-B2EE-7CAF63971D34@defraine.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello,

I'm experiencing a problem with a new version of the PostgreSQL JDBC driver. Under a condition that has got to do with the invocation of getMetaData(), the execution of a prepared statement raises an error "Can't change resolved type for param: 1 from 1043 to 25" (from SimpleParameterList) for (what seems to me) a perfectly valid insert statement.

I've created a simple test case to reproduce the bug. I use the following database:

CREATE DATABASE bug;

\connect bug

CREATE TABLE foo (
id serial PRIMARY KEY,
value text NOT NULL,
date timestamp DEFAULT now() NOT NULL
);

The test case (in attachment) will execute the following insert statement:

insert into foo(value,date) values (?,?) returning id

With the following result:

Driver version: PostgreSQL 8.4 JDBC4 (build 701)
Database version: PostgreSQL 8.4.3 on i386-apple-darwin9.7.0, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465), 32-bit
Exception in thread "main" java.lang.IllegalArgumentException: Can't change resolved type for param: 1 from 1043 to 25
at org.postgresql.core.v3.SimpleParameterList.setResolvedType(SimpleParameterList.java:230)
at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1488)
at org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:1062)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at Bug.triggerBug(Bug.java:31)
at Bug.main(Bug.java:10)

I found that I can do three things to workaround this error at the moment:

1) Include a "prepare threshold" in the URL: jdbc:postgresql:bug?prepareThreshold=1
2) Comment out the call to ps.getMetaData() (but I need that in my actual app)
3) Use an older version of postgresql-jdbc; at least the following worked:

Driver version: PostgreSQL 8.3 JDBC3 with SSL (build 604)
Database version: PostgreSQL 8.4.3 on i386-apple-darwin9.7.0, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465), 32-bit
1

Best regards,
Bruno De Fraine

Attachment Content-Type Size
Bug.java application/octet-stream 1.1 KB

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2010-05-07 16:00:49 Re: Bug: SimpleParameterList and resolved types
Previous Message Lew 2010-05-03 04:26:45 Re: SQLException.getErrorCode ?