Re: Question on Multi-Table Inserts

From: Don Parris <parrisdc(at)gmail(dot)com>
To: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Question on Multi-Table Inserts
Date: 2013-04-19 21:35:51
Message-ID: CAJ-7yonxxy9wp+D0F3Cj1z9RPNbuDFG2OpJxZoPenyQOaaaUSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Thanks all,

Sorry - I got busy the last few days.

On Tue, Apr 16, 2013 at 8:54 AM, Federico Di Gregorio <fog(at)dndg(dot)it> wrote:

> 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
>
>

--
D.C. Parris, FMP, Linux+, ESL Certificate
Minister, Security/FM Coordinator, Free Software Advocate
http://dcparris.net/
<https://www.xing.com/profile/Don_Parris><http://www.linkedin.com/in/dcparris>
GPG Key ID: F5E179BE

In response to

Browse psycopg by date

  From Date Subject
Next Message Don Parris 2013-04-19 22:38:32 Paging Through Query Result Sets
Previous Message Federico Di Gregorio 2013-04-16 12:54:29 Re: Question on Multi-Table Inserts