Re: Multiple tables row insertions from single psql input file

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Multiple tables row insertions from single psql input file
Date: 2024-06-10 21:58:42
Message-ID: 153620cc-69f4-d850-ae36-2224dbd7f5ae@appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2024-06-10 22:00:55 Re: Multiple tables row insertions from single psql input file
Previous Message Peter J. Holzer 2024-06-10 21:27:15 Re: Multiple tables row insertions from single psql input file