Skip site navigation (1) Skip section navigation (2)

Re: PreparedStatement

From: Kris Jurka <books(at)ejurka(dot)com>
To: Nathan Crause <ncrause(at)uniclear(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement
Date: 2004-09-25 19:33:07
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc

On Sat, 25 Sep 2004, Nathan Crause wrote:

> I have a need for the Connection.prepareStatement(String sql, int
> autoGeneratedKeys) method to be functional. Obviously, such keys would
> only ever be generated during an INSERT (as per the Java API
> specification: "This parameter is ignored if the SQL statement is not an
> INSERT statement").

Please see the previous discussion thread starting here:

I know you are just trying to implement something that will make your 
existing application work, but we need something that will work for all 
situations.  There are a number of questions I raise in the thread that no 
one has really answered.  I know you're looking to avoid the trigger 
situation, so let's leave that out for now, but:

How would you return any generated keys for a statement like this:

CREATE TABLE mytable (a serial, b text);

INSERT INTO mytable (b) SELECT (b) FROM mytable;

with multiple rows currval is useless, it can even be useless in the one 
row situation (for a pretty contrived case)

CREATE TABLE mytable (a int default nextval('myseq'), b int default 
nextval('myseq'), c text);

INSERT INTO mytable (c) VALUES ('hi');

When writing a library (as opposed to an application) you need to be 
prepared to handle all sorts of bizarre situations.  At the moment I just 
don't think it's possible to make this method work for anything other than 
a specific subset of situations.

Kris Jurka

In response to


pgsql-jdbc by date

Next:From: Kris JurkaDate: 2004-09-25 19:36:31
Subject: Re: Arrays Question? -Simon Moses
Previous:From: Nathan CrauseDate: 2004-09-25 17:05:17
Subject: PreparedStatement

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group