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:34:06
Message-ID: 4922EE7E.6060706@darwine.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thomas Kellerer schreef:
> Erwin Moller, 18.11.2008 15:47:
>> 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)
>
> That could be resolved with a query against the INFORMATION_SCHEMA
>
> Something like
>
> SELECT c.table_name || ' references ' || tu.table_name
> FROM information_schema.table_constraints c JOIN
> information_schema.constraint_table_usage tu ON
> (c.constraint_name = tu.constraint_name AND c.table_schema =
> tu.table_schema)
> WHERE c.constraint_type = 'FOREIGN KEY';
Hi Thomas,

Thanks!
That is not excactly what I need, but it gets very close. :-)
I think I can use that approach to build a (PHP)script to do the
recursive trick, so it lists all tables that are coupled via-via to the
first table.
Should be straightforward from here.

Thank you.
Regards,
Erwin Moller

>
>> 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'.
>
> That would be your front-end that displays that (or some nested
> self-join using the above statement)
>
> Regards
> Thomas
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-11-18 16:38:38 Re: how can I exclude stuff from template in my dumps?
Previous Message Tom Lane 2008-11-18 16:32:48 Re: Urgent - Grant