From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Benjamin Smith <lists(at)benjamindsmith(dot)com> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Search for restricting foreign keys |
Date: | 2005-01-25 06:18:13 |
Message-ID: | 20050125061813.GA21776@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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/
From | Date | Subject | |
---|---|---|---|
Next Message | sid tow | 2005-01-25 06:48:50 | How to lock or disable a trigger |
Previous Message | Dave Bodenstab | 2005-01-25 06:00:26 | My problem upgrading to 8.0.0 |