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 1sGn2O-00HETI-IX for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 21:58:49 +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 1sGn2N-00Gkld-4T for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 21:58:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGn2M-00GklN-QP for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 21:58:47 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGn2L-00100g-Ai for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 21:58:47 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id BFD1E2A2B7C for ; Mon, 10 Jun 2024 14:58:42 -0700 (PDT) Date: Mon, 10 Jun 2024 14:58:42 -0700 (PDT) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Multiple tables row insertions from single psql input file In-Reply-To: <20240610212715.aqpipehoa5xxmrmf@hjp.at> Message-ID: <153620cc-69f4-d850-ae36-2224dbd7f5ae@appl-ecosys.com> References: <7da8ec9-089-74ce-eb3-c88889b62c64@appl-ecosys.com> <20240610212715.aqpipehoa5xxmrmf@hjp.at> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 10 Jun 2024, Peter J. Holzer wrote: >> My question is whether I can create new rows for all three tables in the >> same sql source file. > > Yes, of course. >> 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? > You will of course have to enter each company before its location and each > company and location before its contact. Otherwise you won't have a value > to insert into the foreign key field(s). Peter, That's what I thought was the case; no way to insert new rows in children tables when the parent is having new rows at the same time. So, I started with the parent (companies) table but psql is telling me there's a syntax error and I don't see it. Testing script: INSERT into companies (company_nbr,company_name,industry,status) VALUES nextval('companies_org_nbr_seq'),'Acme','Manufacturing','Opportunity'), nextval('companies_org_nbr_seq'),'Baker','Livestock','Opportunity'); Running: $ psql -U rshepard -d bustrac -f test-script.sql psql:test-script.sql:3: ERROR: syntax error at or near "nextval" LINE 2: nextval('companies_org_nbr_seq'),'Acme','Manufacturing','Opp... ^ What have I missed? TIA, Rich