From: Michael Fuhr <mike@fuhr.org>
To: Steve Castellotti <SteveC@innocent.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Looking up table names by REFERENCES
Date: Tue, 25 Jan 2005 12:10:45 -0700
Message-ID: <20050125191045.GA78147@winnie.fuhr.org> (raw)
In-Reply-To: <1106579349.746.8.camel@odyssey>
References: <1106579349.746.8.camel@odyssey>
On Tue, Jan 25, 2005 at 04:09:09AM +1300, Steve Castellotti wrote:
> Surely there's a simple way I can trace REFERENCES in a particular
> column across tables?
The pg_constraint table contains foreign key constraints. Here's
an example query that appears to work in trivial tests:
SELECT c.conname,
c.conrelid::regclass, a1.attname,
c.confrelid::regclass, a2.attname AS fattname
FROM pg_constraint AS c
JOIN pg_attribute AS a1 ON a1.attrelid = c.conrelid AND a1.attnum = ANY (c.conkey)
JOIN pg_attribute AS a2 ON a2.attrelid = c.confrelid AND a2.attnum = ANY (c.confkey)
WHERE c.contype = 'f';
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, SteveC@innocent.com
Subject: Re: Looking up table names by REFERENCES
In-Reply-To: <20050125191045.GA78147@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox