Re: INSERT / UPDATE into 2 inner joined table simultaneously

Поиск
Список
Период
Сортировка
От Christopher Swingley
Тема Re: INSERT / UPDATE into 2 inner joined table simultaneously
Дата
Msg-id CAHsw449htrKYSpGa8ZpNh1W+DjZF1=uO3FFGeHvVmK9e2iUEdg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: INSERT / UPDATE into 2 inner joined table simultaneously  (Lou <lou@dayspringpublisher.com>)
Список pgsql-sql
Lou,

On Wed, Mar 6, 2019 at 12:36 PM Lou <lou@dayspringpublisher.com> wrote:
> The data for both tables needs to be saved at the same time so that the id number of table c can be copied into the
c_idfield of table p.
 

I think what you want to do is use a transaction (BEGIN), insert the
data into table c RETURNING id, then insert the data into table p
using the id returned from the first query. If there were no errors,
COMMIT the transaction, otherwise ROLLBACK. It's two queries, but
because of the transaction, it's happening atomically within the
database.

Cheers,

Chris
-- 
Christopher Swingley
Fairbanks, Alaska
http://swingleydev.com/
cswingle@swingleydev.com


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

Предыдущее
От: Lou
Дата:
Сообщение: Re: INSERT / UPDATE into 2 inner joined table simultaneously
Следующее
От: Steve Midgley
Дата:
Сообщение: Re: INSERT / UPDATE into 2 inner joined table simultaneously