Re: Foreign Key 'walker'?

From: Erwin Moller <erwin(at)darwine(dot)nl>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign Key 'walker'?
Date: 2008-11-18 16:01:49
Message-ID: 4922E6ED.4010102@darwine.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

ries van Twisk schreef:
>
> On Nov 18, 2008, at 9:47 AM, Erwin Moller wrote:
>
>> Hi group,
>>
>> Considering following (simplified) example:
>>
>> CREATE TABLE tblnr1(
>> nr1id SERIAL PRIMARY KEY,
>> firstname TEXT
>> );
>> CREATE TABLE tblnr2(
>> nr2id SERIAL PRIMARY KEY,
>> nr1id INTEGER REFERENCES tblnr1(nr1id)
>> );
>> CREATE TABLE tblnr3(
>> nr3id SERIAL PRIMARY KEY,
>> nr2id INTEGER REFERENCES tblnr2(nr2id)
>> );
>>
>> 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)
>> 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)
>> 2) I have a lot of tables and am afraid I miss some. And I am also a
>> bit lazy .-)
>>
>
> Why not use something like this??
>
> CONSTRAINT fk_tname FOREIGN KEY (nr2id)
> REFERENCES tblnr2 MATCH SIMPLE ON UPDATE CASCADE ON DELETE NO
> ACTION,
Hi,

Thankf for your reply, but that is NOT what I am looking for.

I want to list the tables that use REFERENCES etc. against my first table.
And deeper (so if other tables references second table then I would like
them too). etc.

Regards,
Erwin Moller

>
>> Thanks for your time.
>>
>> Regards,
>> Erwin Moller
>>
>
>
>
>
>
>
>
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pietro Tedesco 2008-11-18 16:09:01 High Availability for PostgreSQL on Windows 2003.
Previous Message Thomas Kellerer 2008-11-18 15:47:49 Re: Foreign Key 'walker'?