Question on Multi-Table Inserts

Поиск
Список
Период
Сортировка
От Don Parris
Тема Question on Multi-Table Inserts
Дата
Msg-id CAJ-7yokqa4Aynm85LRDR1yofU-yFXLLqYJvk8Dp57RNxz97hpQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Question on Multi-Table Inserts
Re: Question on Multi-Table Inserts
Список 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
GPG Key ID: F5E179BE

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

Предыдущее
От: David Gilman
Дата:
Сообщение: Building psycopg2 under cygwin
Следующее
От: Joe Abbate
Дата:
Сообщение: Re: Question on Multi-Table Inserts