Re: Foreign Key 'walker'?

From: ries van Twisk <pg(at)rvt(dot)dds(dot)nl>
To: Erwin Moller <erwin(at)darwine(dot)nl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign Key 'walker'?
Date: 2008-11-18 14:58:11
Message-ID: DD2D0AB6-7683-4D3E-B943-F025FB5E9B00@rvt.dds.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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,

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephane Bortzmeyer 2008-11-18 15:01:59 Re: Urgent - Grant
Previous Message Erwin Moller 2008-11-18 14:47:04 Foreign Key 'walker'?