Re: fields and foreign keys - Mailing list pgsql-general

From Michael Fuhr
Subject Re: fields and foreign keys
Date
Msg-id 20050623152308.GA36909@winnie.fuhr.org
Whole thread Raw
In response to fields and foreign keys  ("mrix" <gmarik@gmail.com>)
List pgsql-general
On Thu, Jun 23, 2005 at 01:34:28AM -0700, mrix wrote:
>
> I'd like to know how can i get list of fields and corresponding foreign
> keys (referenced table and field).

For individual tables, client interfaces usually have a way to show
the table definition.  In psql, for example, you can use "\d tablename".
If you want to see all foreign key constraints for all tables then
you could query the pg_constraint system catalog.

http://www.postgresql.org/docs/8.0/static/catalog-pg-constraint.html

You can get an idea of what query to issue by viewing the hidden commands
that psql executes (run "psql -E" or execute "\set ECHO_HIDDEN" and then
execute "\d tablename").  Here's an example:

SELECT conrelid::regclass, conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE contype = 'f';

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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Corrupted index
Next
From: Michael Fuhr
Date:
Subject: Re: plpgsql and schema