Re: INSERT / UPDATE into 2 inner joined table simultaneously - Mailing list pgsql-sql

From Christopher Swingley
Subject Re: INSERT / UPDATE into 2 inner joined table simultaneously
Date
Msg-id CAHsw449htrKYSpGa8ZpNh1W+DjZF1=uO3FFGeHvVmK9e2iUEdg@mail.gmail.com
Whole thread Raw
In response to Re: INSERT / UPDATE into 2 inner joined table simultaneously  (Lou <lou@dayspringpublisher.com>)
List 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 by date:

Previous
From: Lou
Date:
Subject: Re: INSERT / UPDATE into 2 inner joined table simultaneously
Next
From: Steve Midgley
Date:
Subject: Re: INSERT / UPDATE into 2 inner joined table simultaneously