Re: FK relationships - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: FK relationships
Date
Msg-id 20050112193107.GA95870@winnie.fuhr.org
Whole thread Raw
In response to FK relationships  (sarlav kumar <sarlavk@yahoo.com>)
Responses Re: FK relationships
List pgsql-novice
On Wed, Jan 12, 2005 at 10:56:00AM -0800, sarlav kumar wrote:

> Is there an easy way to find out the list of tables that have a
> FK relation on a particular table?

You could query the system catalogs, either directly or via the
Information Schema (the latter is available in 7.4 and later).
See the "System Catalogs" and "The Information Schema" chapters
in the documentation.

> Say, if I have a 'customer' table, I would like to get the tables
> that depend on customer and not the tables on which customer depends.

I think this'll work, although I did only trivial testing with it:

SELECT conrelid::regclass, conname
FROM pg_constraint
WHERE confrelid = 'customer'::regclass AND contype = 'f';

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-novice by date:

Previous
From: sarlav kumar
Date:
Subject: FK relationships
Next
From: sarlav kumar
Date:
Subject: Re: FK relationships