Re: fields and foreign keys

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: mrix <gmarik(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: fields and foreign keys
Date: 2005-06-23 15:23:08
Message-ID: 20050623152308.GA36909@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-06-23 15:28:49 Re: Help me urgently
Previous Message Tom Lane 2005-06-23 14:36:14 Re: Corrupted index