From: Kris Jurka <books@ejurka.com>
To: Eric Faulhaber <ecf@goldencode.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Batch INSERT failing with error 22P02
Date: Fri, 21 Sep 2007 02:43:16 -0400 (EDT)
Message-ID: <Pine.BSO.4.64.0709210227150.1423@leary.csoft.net> (raw)
In-Reply-To: <Pine.BSO.4.64.0709201251280.22675@leary.csoft.net>
References: <46EEE4EF.80608@goldencode.com>
<Pine.BSO.4.64.0709171802240.11213@leary.csoft.net>
<46EFF277.1090309@goldencode.com>
<Pine.BSO.4.64.0709181916350.449@leary.csoft.net>
<46F29BBC.20400@goldencode.com>
<Pine.BSO.4.64.0709201251280.22675@leary.csoft.net>
On Thu, 20 Sep 2007, Kris Jurka wrote:
> For the logging information, please rerun with loglevel=2 and upload
> just the last 10k lines of the file.
>
OK, with that info I'v finally managed to generate a reproducible test
case (attached). What happens is the driver sends:
Parse S_1
Describe S_1
Parse S_2
Sync
and when we get the results of S_1's describe we assign it to S_2
because there's only one active query at any time. So we've prepared
S_2 with one set of parameters, but now it thinks it was prepared with
S_1's. So next time we do:
Describe S_2
Sync
We get describe results which come from the server and have what S_2 was
parsed with and that doesn't match up with what the driver has for S_2 and
it bails out.
So the fix is probably to check that we aren't setting type information
from stale results, but this is a pretty complicated area, so I'd like to
study it a little more.
In any case, thanks for your help in tracking this one down.
Kris Jurka
Attachments:ParamTypeProb.java (text/plain, 791B) download
import java.sql.*;
public class ParamTypeProb {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5820/jurka?loglevel=2&prepareThreshold=1", "jurka","");
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMP TABLE tt (a text, b date)");
stmt.close();
PreparedStatement ps = conn.prepareStatement("INSERT INTO tt VALUES (?, ?)");
ps.setString(1, "a");
ps.setDate(2, new Date(0));
ps.addBatch();
ps.setClob(1, null);
ps.setNull(2, Types.DATE);
ps.addBatch();
ps.executeBatch();
ps.setString(1, "b");
ps.setDate(2, new Date(0));
ps.executeUpdate();
ps.close();
conn.close();
}
}
log.txt (text/plain, 4.1K) download
00:32:14.407 (1) PostgreSQL 8.3devel JDBC3g with SSL (build 601)
00:32:14.415 (1) Trying to establish a protocol version 3 connection to localhost:5820
00:32:14.435 (1) FE=> StartupPacket(user=jurka, database=jurka, client_encoding=UNICODE, DateStyle=ISO)
00:32:14.439 (1) <=BE AuthenticationOk
00:32:14.454 (1) <=BE ParameterStatus(client_encoding = UNICODE)
00:32:14.454 (1) <=BE ParameterStatus(DateStyle = ISO, MDY)
00:32:14.454 (1) <=BE ParameterStatus(integer_datetimes = off)
00:32:14.455 (1) <=BE ParameterStatus(is_superuser = on)
00:32:14.455 (1) <=BE ParameterStatus(server_encoding = LATIN1)
00:32:14.455 (1) <=BE ParameterStatus(server_version = 8.2rc1)
00:32:14.455 (1) <=BE ParameterStatus(session_authorization = jurka)
00:32:14.455 (1) <=BE ParameterStatus(standard_conforming_strings = off)
00:32:14.455 (1) <=BE ParameterStatus(TimeZone = Navajo)
00:32:14.455 (1) <=BE BackendKeyData(pid=18476,ckey=1848590853)
00:32:14.456 (1) <=BE ReadyForQuery(I)
00:32:14.456 (1) compatible = 8.3
00:32:14.456 (1) loglevel = 2
00:32:14.456 (1) prepare threshold = 1
getConnection returning driver[className=org.postgresql.Driver,org.postgresql.Driver@2fe4cbc4]
00:32:14.482 (1) simple execute, handler=org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler@70329f3d, maxRows=0, fetchSize=0, flags=17
00:32:14.482 (1) FE=> Parse(stmt=null,query="CREATE TEMP TABLE tt (a text, b date)",oids={})
00:32:14.483 (1) FE=> Bind(stmt=null,portal=null)
00:32:14.483 (1) FE=> Describe(portal=null)
00:32:14.483 (1) FE=> Execute(portal=null,limit=0)
00:32:14.483 (1) FE=> Sync
00:32:14.501 (1) <=BE ParseComplete [null]
00:32:14.501 (1) <=BE BindComplete [null]
00:32:14.501 (1) <=BE NoData
00:32:14.501 (1) <=BE CommandStatus(CREATE TABLE)
00:32:14.502 (1) <=BE ReadyForQuery(I)
00:32:14.504 (1) batch execute 2 queries, handler=org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler@43256ea2, maxRows=0, fetchSize=0, flags=20
00:32:14.504 (1) FE=> Parse(stmt=S_1,query="INSERT INTO tt VALUES ($1, $2)",oids={1043,0})
00:32:14.505 (1) FE=> Describe(statement=S_1) param types = 1043 0
00:32:14.505 (1) FE=> Bind(stmt=S_1,portal=null,$1=<a>,$2=<1969-12-31 -07:00:00>)
00:32:14.505 (1) FE=> Execute(portal=null,limit=1)
00:32:14.506 (1) FE=> Parse(stmt=S_2,query="INSERT INTO tt VALUES ($1, $2)",oids={26,1082})
00:32:14.506 (1) FE=> Bind(stmt=S_2,portal=null,$1=<NULL>,$2=<NULL>)
00:32:14.506 (1) FE=> Describe(portal=null)
00:32:14.506 (1) FE=> Execute(portal=null,limit=1)
00:32:14.506 (1) FE=> Sync
00:32:14.508 (1) <=BE ParseComplete [S_1]
00:32:14.509 (1) <=BE ParameterDescription 1043 1082
00:32:14.509 (1) <=BE NoData
00:32:14.509 (1) <=BE BindComplete [null]
00:32:14.509 (1) <=BE CommandStatus(INSERT 0 1)
00:32:14.509 (1) <=BE ParseComplete [S_2]
00:32:14.509 (1) <=BE BindComplete [null]
00:32:14.509 (1) <=BE NoData
00:32:14.510 (1) <=BE CommandStatus(INSERT 0 1)
00:32:14.510 (1) <=BE ReadyForQuery(I)
00:32:14.510 (1) simple execute, handler=org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler@33dff3a2, maxRows=0, fetchSize=0, flags=20
00:32:14.510 (1) FE=> CloseStatement(S_1)
00:32:14.510 (1) FE=> Describe(statement=S_2) param types = 1043 0
00:32:14.510 (1) FE=> Bind(stmt=S_2,portal=null,$1=<b>,$2=<1969-12-31 -07:00:00>)
00:32:14.510 (1) FE=> Execute(portal=null,limit=1)
00:32:14.510 (1) FE=> Sync
00:32:14.511 (1) <=BE CloseComplete
00:32:14.511 (1) <=BE ParameterDescription 26 1082
Exception in thread "main" java.lang.IllegalArgumentException: Can't change resolved type for parameter: 1 Orig types: 1043 0 New Types: 26 1082
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1227)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:190)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:304)
at ParamTypeProb.main(ParamTypeProb.java:26)
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: books@ejurka.com, ecf@goldencode.com
Subject: Re: Batch INSERT failing with error 22P02
In-Reply-To: <Pine.BSO.4.64.0709210227150.1423@leary.csoft.net>
References: <46EEE4EF.80608@goldencode.com> <Pine.BSO.4.64.0709171802240.11213@leary.csoft.net> <46EFF277.1090309@goldencode.com> <Pine.BSO.4.64.0709181916350.449@leary.csoft.net> <46F29BBC.20400@goldencode.com> <Pine.BSO.4.64.0709201251280.22675@leary.csoft.net> <Pine.BSO.4.64.0709210227150.1423@leary.csoft.net>
* 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