Re: Multiple tables row insertions from single psql input file

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Multiple tables row insertions from single psql input file
Date: 2024-06-10 19:42:56
Message-ID: CANzqJaAXnwh-n0K_JhGiGja2vdqFvRvffdwe2RkVAVKLbmH69g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jun 10, 2024 at 2:50 PM Rich Shepard <rshepard(at)appl-ecosys(dot)com>
wrote:

> 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?
>

With enough clever scripting you can create a .sql file that does almost
anything.

Most useful to you will be some number of "ALTER TABLE <foo> DISABLE
TRIGGER ALL;" statements near the beginning of the file, and their "ALTER
TABLE ... ENABLE TRIGGER ALL;" counterparts near the end of the file.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Torsten Förtsch 2024-06-10 20:02:26 Re: Multiple tables row insertions from single psql input file
Previous Message veem v 2024-06-10 19:17:14 Does trigger only accept functions?