Re: PostgreSQL - Ordering Table based of Foreign Key

From: FOUTE K(dot) Jaurès <jauresfoute(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: PostgreSQL - Ordering Table based of Foreign Key
Date: 2021-10-04 11:02:41
Message-ID: CAHQ1jffOQ4-yB0X9JB6LN2+U08UyE86b_BtZTva7+A90gNghPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

Thx for all the feedback.
After googling that, I saw this link that can be a way I can go.
https://stackoverflow.com/questions/51279588/sort-tables-in-order-of-dependency-postgres
<https://stackoverflow.com/questions/51279588/sort-tables-in-order-of-dependency-postgres>

Le dim. 3 oct. 2021 à 22:33, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
a écrit :

>
>
> On Sun, Oct 3, 2021, 00:48 FOUTE K. Jaurès <jauresfoute(at)gmail(dot)com> wrote:
>
>> Hello,
>>
>> 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"
>>
>
> As others have said this is why on delete cascade exists. Unfortunately
> this does require some advanced planning as changing it on the fly doesn't
> really work.
>
> I do not believe there is a built-in way to return an ordered listing of
> dependent relations given a base relation as an input. But the catalog
> entries do exist should you wish to build such yourself.
>
> That said maybe deferred constraint evaluation will work so that at least
> the order doesn't matter. But you still.would.need to know which tables to
> write delete commands for.
>
> There is some recent discussion on making this work in a more
> user-friendly away but that would be only available in v15 at best.
>
> David J.
>
>
>>

--
Jaurès FOUTE

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shaozhong SHI 2021-10-04 11:18:40 How to set up temporary path for starting up psql in any folder?
Previous Message Dennis Jacobfeuerborn 2021-10-04 10:45:24 Re: Why would Postgres 11 suddenly ignore the recovery.conf file?