Help with transactions and FK's

Поиск
Список
Период
Сортировка
От Michael Schmidt
Тема Help with transactions and FK's
Дата
Msg-id BAY114-DAV6AA655FD12941EE9D9740A3F40@phx.gbl
обсуждение исходный текст
Ответы Re: Help with transactions and FK's  (Dave Cramer <pg@fastcrypt.com>)
Список pgsql-jdbc
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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: JDBC Support for standard_conforming_strings
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Help with transactions and FK's