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

From Rich Shepard
Subject Multiple tables row insertions from single psql input file
Date
Msg-id 7da8ec9-089-74ce-eb3-c88889b62c64@appl-ecosys.com
Whole thread Raw
Responses Re: Multiple tables row insertions from single psql input file
Re: Multiple tables row insertions from single psql input file
Re: Multiple tables row insertions from single psql input file
List pgsql-general
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



pgsql-general by date:

Previous
From: Dominique Devienne
Date:
Subject: Re: libpq v17 PQsocketPoll timeout is not granular enough
Next
From: veem v
Date:
Subject: Does trigger only accept functions?