From: | Don Parris <parrisdc(at)gmail(dot)com> |
---|---|
To: | "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org> |
Subject: | Question on Multi-Table Inserts |
Date: | 2013-04-16 09:59:08 |
Message-ID: | CAJ-7yokqa4Aynm85LRDR1yofU-yFXLLqYJvk8Dp57RNxz97hpQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
Hi all,
This is more of a strategic question. If I want to enter a particular
financial transaction in my DB, I need to use the following process:
Insert a new or select an existing payee
Insert a new transaction record (using the payee_id from the payee table)
Insert at least one, but usually more line items (using the transrec_id
from the transrec table)
Insert a new or select an existing category for the transaction line item
(using the cat_id) from the category table.
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?
Thanks!
Don
--
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
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Abbate | 2013-04-16 11:02:26 | Re: Question on Multi-Table Inserts |
Previous Message | David Gilman | 2013-04-11 20:52:09 | Building psycopg2 under cygwin |