Re: Bulk inserts into two (related) tables

From: Will Hartung <willhartung(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Bulk inserts into two (related) tables
Date: 2019-05-21 18:27:10
Message-ID: AA54311D-DA70-4792-98FE-5F88ABFAEF20@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> On May 21, 2019, at 9:56 AM, Rich Shepard <rshepard(at)appl-ecosys(dot)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’))

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-05-21 18:27:33 Re: Re: Re: Refresh Publication takes hours and doesn´t finish
Previous Message Ron 2019-05-21 18:06:43 Re: Bulk inserts into two (related) tables