Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hT9VX-0003fi-Nh for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 18:29:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hT9VW-0001Ix-ID for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 18:29:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hT9VW-0001CE-33 for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 18:29:02 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hT9VT-0006jR-R7 for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 18:29:00 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id A720799387 for ; Tue, 21 May 2019 11:28:58 -0700 (PDT) Date: Tue, 21 May 2019 11:28:58 -0700 (PDT) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Bulk inserts into two (related) tables In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 21 May 2019, Will Hartung wrote: > 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’)) Thanks, Will. That's a good alternative. Regards, Rich