X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C90C1D7B17 for ; Tue, 8 Nov 2005 11:58:26 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33903-03 for ; Tue, 8 Nov 2005 15:58:20 +0000 (GMT) X-Greylist: delayed 03:05:12.63244 by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by svr1.postgresql.org (Postfix) with ESMTP id 4F4DBD7018 for ; Tue, 8 Nov 2005 11:58:21 -0400 (AST) Received: from cuaima.ica.luz.ve (unknown [150.185.222.161]) by svr2.postgresql.org (Postfix) with ESMTP id 1009DF0FDC for ; Tue, 8 Nov 2005 12:53:12 +0000 (GMT) Received: from tragavenado.luz.edu.ve (tragavenado.ica.luz.ve [10.2.208.202]) by cuaima.ica.luz.ve (Postfix) with ESMTP id 24D52700DB for ; Tue, 8 Nov 2005 08:50:26 -0400 (VET) From: Nelson Arape To: pgsql-jdbc@postgresql.org Subject: Re: Batch with keygen? Date: Tue, 8 Nov 2005 08:50:14 -0400 User-Agent: KMail/1.8.3 References: <06B12D1D68BCCA4CB1F60BB4EA509768245476@pq-exch01.actional.com> <1967C9F5-1F3C-4AEB-B757-87193EAD5207@fastcrypt.com> In-Reply-To: <1967C9F5-1F3C-4AEB-B757-87193EAD5207@fastcrypt.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200511080850.14947.narape@ica.luz.ve> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.015 required=5 tests=[AWL=0.015] X-Spam-Score: 0.015 X-Spam-Level: X-Archive-Number: 200511/49 X-Sequence-Number: 14147 Maybe I am a bit off, but the old friends curval() and nextval() don't do t= he=20 trick? I mean con.setAutoCommit(false); Statement stmt =3D con.createStatement(); stmt.addBatch("INSERT INTO TABLEA " + "VALUES(nextval('TABLEA_PK_SEQ'), 1, 2, 3)"); stmt.addBatch("INSERT INTO TABLEB " + "VALUES(curval('TABLEA_PK_SEQ'), 4, 5, 6)"); =2E.. int [] updateCounts =3D stmt.executeBatch(); Bye Nelson Arap=E9 PS: sorry for my English El Lun 07 Nov 2005 20:01, Dave Cramer escribi=F3: > Additionally you should be aware, that using this mechanism once a > connection gets a hundred values, they are consumed even if you don't > use them. > > Dave > > On 7-Nov-05, at 4:18 PM, Kris Jurka wrote: > > On Mon, 7 Nov 2005, Mike Clements wrote: > >> I've got a bunch of PreparedStatements doing inserts on tables with > >> primary keys generated by sequences. For example, insert on table A, > >> take generated primary key, insert on table B assigning foreign key > >> generated value for A's primary key. > >> > >> For performance reasons, I need to batch these commands. But I > >> don't see > >> how it would be possible to continue using this approach with a > >> batch of > >> commands, because I need the results of the first insert to make the > >> second insert. Is there some way to do this or am I going to have to > >> stop using keygen and instead have my application generate its own > >> keys? > > > > One option would be to tune your sequence generator to your batch > > size, consider: CREATE SEQUENCE myseq INCREMENT BY 100; Then if > > you fetch a nextval you know that you are also free to use the next > > 99 values as well in your batch statement without touching the > > sequence. > > > > Kris Jurka > > > > ---------------------------(end of > > broadcast)--------------------------- > > TIP 6: explain analyze is your friend > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match