Re: Question on Multi-Table Inserts - Mailing list psycopg

From Federico Di Gregorio
Subject Re: Question on Multi-Table Inserts
Date
Msg-id 516D4A05.4000300@dndg.it
Whole thread Raw
In response to Question on Multi-Table Inserts  (Don Parris <parrisdc@gmail.com>)
Responses Re: Question on Multi-Table Inserts
List psycopg
On 16/04/2013 11:59, Don Parris wrote:
[snip]
> Is it as simple as running a series of insert statements in succession,
> passing on the PK of the first table to the next table in the process?
> I.e.,
>
> BEGIN
> INSERT into table payee(values...)
> INSERT into table transrec(values...) # pass in payee_id variable
> SELECT *from category (to get cat_id)
> INSERT into table transdetails(values...) #pass in transrec_id and
> cat_id variables
> COMMIT
>
> Or is it more complicated than that?

If your only data store is the database then using a transaction is the
right thing to do. Being all-or-nothing you get exactly what you want.

federico



psycopg by date:

Previous
From: Joe Abbate
Date:
Subject: Re: Question on Multi-Table Inserts
Next
From: Don Parris
Date:
Subject: Re: Question on Multi-Table Inserts