Re: Multiple tables row insertions from single psql input file - Mailing list pgsql-general

From Rich Shepard
Subject Re: Multiple tables row insertions from single psql input file
Date
Msg-id 153620cc-69f4-d850-ae36-2224dbd7f5ae@appl-ecosys.com
Whole thread Raw
In response to Re: Multiple tables row insertions from single psql input file  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
Responses Re: Multiple tables row insertions from single psql input file
List pgsql-general
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



pgsql-general by date:

Previous
From: "Peter J. Holzer"
Date:
Subject: Re: Multiple tables row insertions from single psql input file
Next
From: "David G. Johnston"
Date:
Subject: Re: Multiple tables row insertions from single psql input file