Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id A63559FA12B for ; Mon, 13 Nov 2006 13:06:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 02406-05 for ; Mon, 13 Nov 2006 13:06:05 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 563FC9FA0B9 for ; Mon, 13 Nov 2006 13:06:05 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from bay0-omc2-s2.bay0.hotmail.com (bay0-omc2-s2.bay0.hotmail.com [65.54.246.138]) by svr4.postgresql.org (Postfix) with ESMTP id 564B35AF027 for ; Mon, 13 Nov 2006 17:06:04 +0000 (GMT) Received: from hotmail.com ([65.54.169.78]) by bay0-omc2-s2.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 13 Nov 2006 09:06:02 -0800 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 13 Nov 2006 09:06:02 -0800 Message-ID: Received: from 71.219.233.198 by BAY114-DAV6.phx.gbl with DAV; Mon, 13 Nov 2006 17:05:58 +0000 X-Originating-IP: [71.219.233.198] X-Originating-Email: [michaelmschmidt@msn.com] X-Sender: michaelmschmidt@msn.com From: "Michael Schmidt" To: "PostgreSQL JDBC" Subject: Help with transactions and FK's Date: Mon, 13 Nov 2006 10:05:57 -0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0003_01C7070B.50286DD0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: MSN 9 Seal-Send-Time: Mon, 13 Nov 2006 10:05:57 -0700 X-MimeOLE: Produced By MSN MimeOLE V9.20.0029.3000 X-OriginalArrivalTime: 13 Nov 2006 17:06:02.0046 (UTC) FILETIME=[FF48FDE0:01C70745] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.22 tagged_above=0 required=5 tests=BAYES_40, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, HTML_40_50, HTML_MESSAGE, MSGID_FROM_MTA_HEADER X-Spam-Level: ** X-Archive-Number: 200611/65 X-Sequence-Number: 16107 This is a multi-part message in MIME format. ------=_NextPart_000_0003_01C7070B.50286DD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Folks, I'm sure this is a basic question, but after reading the PG = documentation and some posts on the lists, I still haven't found a = solution. So, I hope someone can provide an answer without too much = effort. I have a scientific bibliography database in which a "data item" = consists of a parent record with several child and grandchild records, = linked with foreign keys. Using my Java front-end and JDBC, I want to = insert a new "data item" via a transaction. My thought is to do the = following steps: SET TRANSACTION insert the parent record get the parent record primary key with currval() of the primary key = sequence set the child record foreign key value to the value from currval() insert the child records COMMIT roll back on error for the grandchild records, several currval() calls will be needed. My = question is - will currval() provide the correct primary key value for = the records inserted in the transaction, or will it provide the value of = the sequence at the beginning of the transaction? If the latter, how to = proceed? Thanks for your time. Michael Schmidt ------=_NextPart_000_0003_01C7070B.50286DD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Folks,
I'm sure this is a basic question, but after reading the PG = documentation=20 and some posts on the lists, I still haven't found a solution.  So, = I hope=20 someone can provide an answer without too much effort.
 
I have a scientific bibliography database in which a "data item" = consists=20 of a parent record with several child and grandchild records, linked = with=20 foreign keys.  Using my Java front-end and JDBC, I want to insert a = new=20 "data item" via a transaction.  My thought is to do the following=20 steps:
 
SET TRANSACTION
insert the parent record
get the parent record primary key with currval() of the = primary key=20 sequence
set the child record foreign key value to the value from = currval()
insert the child records
COMMIT
roll back on error
 
for the grandchild records, several currval() calls will be = needed. =20 My question is - will currval() provide the correct primary key = value for=20 the records inserted in the transaction, or will it provide the value of = the=20 sequence at the beginning of the transaction?  If the latter, how = to=20 proceed?
 
Thanks for your time.
Michael Schmidt
------=_NextPart_000_0003_01C7070B.50286DD0--