Re: Search for restricting foreign keys - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Search for restricting foreign keys
Date
Msg-id 20050125061813.GA21776@winnie.fuhr.org
Whole thread Raw
In response to Search for restricting foreign keys  (Benjamin Smith <lists@benjamindsmith.com>)
Responses Re: Search for restricting foreign keys  ("Florian G. Pflug" <fgp@phlo.org>)
List pgsql-general
On Mon, Jan 24, 2005 at 08:35:45PM -0800, Benjamin Smith wrote:

> Is there a way in PG 7.3, given a field, to find out what other tables &
> records are linked to it via a foreign key?

See the "System Catalogs" chapter in the documentation:

http://www.postgresql.org/docs/7.3/static/catalogs.html

The pg_constraint table contains, among other things, foreign key
constraints.  By querying it and joining it with pg_attribute,
pg_class, and pg_namespace, you could get a list of tables and
columns that have foreign key constraints on the given table and
column; from that you could build queries to find out which rows
in those tables match the given value.  You could wrap all this
code in a set-returning function.

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

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: disable trigger from transaction
Next
From: sid tow
Date:
Subject: How to lock or disable a trigger