Re: Foreign Key 'walker'?

From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: ries van Twisk <pg(at)rvt(dot)dds(dot)nl>
Cc: Erwin Moller <erwin(at)darwine(dot)nl>, pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign Key 'walker'?
Date: 2008-11-18 17:20:19
Message-ID: 4922F953.6080306@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

ries van Twisk wrote:
>
> On Nov 18, 2008, at 9:47 AM, Erwin Moller wrote:
>
>> Hi group,
>>
>> Considering following (simplified) example:
<snip>
>>
>> Suppose I want to delete a record in tblnr1.
>> Does Postgres has some command/procedure/function to list tables that
>> have FK constraints on that table (tblnr1)

The data you are looking for is stored in the system catalogs.
http://www.postgresql.org/docs/8.3/interactive/catalogs.html
You should be able to come up with some SELECT's to get what you want.

>> and lists also the tables that have a FK constraint on tables that
>> have a FK constraint on the first? etc.
>> So I would like some kind of FK 'walker'.
>>
>> I want this because:
>> 1) I hate DELETE CASCADE because I am chicken (So I use a script to
>> delete all related records in the right order in a transaction)

That isn't being chicken it is being silly (or is that just stubborn ;).
PostgreSQL is designed to delete related records that you tell it to
delete. Let it do what it is suppose to do.

>> 2) I have a lot of tables and am afraid I miss some. And I am also a
>> bit lazy .-)

If your lazy why do all this manual work when you can leave it
automated? It won't miss a related record after you tell it to cascade
delete. This is an old well tested feature that you can rely on.

That probably all sounds more aggressive than it should. Not having a
strong dig at you but I do want to emphasise the fact that you shouldn't
waste your time doing manually what the software is designed to do.

--

Shane Ambler
pgSQL (at) Sheeky (dot) Biz

Get Sheeky @ http://Sheeky.Biz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Simon Connah 2008-11-18 17:24:14 No serial type
Previous Message Alvaro Herrera 2008-11-18 17:15:28 Re: pgsql-general@postgresql.org