Re: Bulk inserts into two (related) tables - Mailing list pgsql-general

From Will Hartung
Subject Re: Bulk inserts into two (related) tables
Date
Msg-id AA54311D-DA70-4792-98FE-5F88ABFAEF20@gmail.com
Whole thread Raw
In response to Bulk inserts into two (related) tables  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: Bulk inserts into two (related) tables
List pgsql-general

On May 21, 2019, at 9:56 AM, Rich Shepard <rshepard@appl-ecosys.com> wrote:

I could insert all new rows into the organizations table, then produce a
list of the org_id and org_name to manually insert the foreign key in the
related people table. Time and effort intense.

You can either use a script for the entire process, or, convert the people table to INSERT statements that have a SELECT for the foreign key as part of the insert.

INSERT INTO PEOPLE (id, name, org_id) VALUES (1, ‘Bob’, (SELECT org_id FROM org WHERE org_name=‘Main Office’))


pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: Bulk inserts into two (related) tables
Next
From: Tom Lane
Date:
Subject: Re: Re: Re: Refresh Publication takes hours and doesn´t finish