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 1hT84D-0007sj-8b for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 16:56:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hT84C-0001HV-01 for pgsql-general@arkaria.postgresql.org; Tue, 21 May 2019 16:56:44 +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 1hT84B-0001HM-I6 for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 16:56:43 +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 1hT848-0004dC-Os for pgsql-general@lists.postgresql.org; Tue, 21 May 2019 16:56:42 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id A300A99387 for ; Tue, 21 May 2019 09:56:38 -0700 (PDT) Date: Tue, 21 May 2019 09:56:38 -0700 (PDT) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Bulk inserts into two (related) tables Message-ID: User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I'm cleaning and formatting a 800-line data file to be inserted into a database. Some of the input file fields will be inserted into an 'organizations' table letting postgres assign sequential org_id numbers. Other fields will be inserted into a separate 'people' table associated with each organization. The people table insert allows postgres to assign the person_id number and this table's foreign key, people.org_id == organizations.org_id. 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. Is there a way to insert the two tables sequentially without manually adding the organizations.org_id to the appropriate foreign key column (people.org_id) of the people table? Rich