dbTalk Databases Forums  

Transactions

comp.databases.postgresql comp.databases.postgresql


Discuss Transactions in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
The Other Guy
 
Posts: n/a

Default Transactions - 01-26-2007 , 07:02 PM






I have a need to enter values in to multiple tables in a database. These
need to be related together by the ID of the last item inserted in to
one of the tables.

I will be using the C API to insert the data in the tables.

One option is to construct the entire series of insert statements for
one call to the database, which I understand will create an implied
transaction. If I do that, how can I get the ID of the last inserted
object in the first table for use in the second?

The other option is to do the initial insert, obtain the last insert ID,
and convert this from the OID to the value by way of another query. The
problem with this is I am unable to do this as a single call. Can I
instead simply call Postgres to start the transaction, send several
statements, and finish the transaction, or will this not work using the
C API?

Thanks,

The Other Guy

Reply With Quote
  #2  
Old   
The Other Guy
 
Posts: n/a

Default Re: Transactions - 01-27-2007 , 01:15 PM






The Other Guy wrote:
Quote:
The other option is to do the initial insert, obtain the last insert ID,
and convert this from the OID to the value by way of another query. The
problem with this is I am unable to do this as a single call. Can I
instead simply call Postgres to start the transaction, send several
statements, and finish the transaction, or will this not work using the
C API?
I found the answer in the example code. I can simply call PQexec with
"BEGIN" and go from there.

The Other Guy


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.