public inbox for [email protected]
help / color / mirror / Atom feedFrom: Rich Shepard <[email protected]>
To: [email protected]
Subject: Re: Multiple tables row insertions from single psql input file
Date: Mon, 10 Jun 2024 14:58:42 -0700 (PDT)
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
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
view thread (3+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Multiple tables row insertions from single psql input file
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox