Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGk6C-00Gd8H-TR for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 18:50:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGk6B-00EzSv-7c for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 18:50:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGk6A-00EzQ3-Sc for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 18:50:31 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGk69-000fni-7O for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 18:50:30 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 784832A2B7C for ; Mon, 10 Jun 2024 11:50:27 -0700 (PDT) Date: Mon, 10 Jun 2024 11:50:27 -0700 (PDT) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Multiple tables row insertions from single psql input file Message-ID: <7da8ec9-089-74ce-eb3-c88889b62c64@appl-ecosys.com> 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: Archived-At: Precedence: bulk My business tracking database has three main tables: company, location, contact. The company and contact primary keys are sequences. I've been adding new rows using INSERT INTO files separately for each table after manually finding the last PK for the company and contact tables. The location table has the company PK as a FK; the contact table has both company PK and location PK as foreign keys. Now I will use next_val 'PK' to assign the value for each new table row. My question is whether I can create new rows for all three tables in the same sql source file. Since the location and contact tables require sequence numbers from the company and location tables is there a way to specify, e.g., current_val 'tablename PK' for the related tables? Or, do I still need to enter all new companies before their locations and contact? TIA, Rich