From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: PostgreSQL - Ordering Table based of Foreign Key
Date: Sun, 3 Oct 2021 10:49:49 +0200
Message-ID: <553c3b6b-93f0-591e-2a48-0c8ab5344d13@gmx.net> (raw)
In-Reply-To: <CAHQ1jfekP6=H-sEzBucctW4kF-jWyEo_rXRDGVsth3EtMQ5aSg@mail.gmail.com>
References: <CAHQ1jfekP6=H-sEzBucctW4kF-jWyEo_rXRDGVsth3EtMQ5aSg@mail.gmail.com>
FOUTE K. Jaurès schrieb am 03.10.2021 um 09:48:
> I want to order tables based on the foreign key so that I can delete
> tables one by one without facing "ERROR: update or delete on table
> "table" violates foreign key constraint. DETAIL: Key is still
> referenced from table"
You can create the foreign key constraints with the "ON DELETE CASCADE" option.
Then Postgres will handle dependencies automatically for you.
But that means that *all* DELETEs will be cascaded.
Unfortunately, there is no DELETE FROM ... CASCADE option (similar to DROP)
Thomas
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: shammat@gmx.net
Subject: Re: PostgreSQL - Ordering Table based of Foreign Key
In-Reply-To: <553c3b6b-93f0-591e-2a48-0c8ab5344d13@gmx.net>
References: <CAHQ1jfekP6=H-sEzBucctW4kF-jWyEo_rXRDGVsth3EtMQ5aSg@mail.gmail.com> <553c3b6b-93f0-591e-2a48-0c8ab5344d13@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox