Re: fields and foreign keys

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: fields and foreign keys
Дата
Msg-id 20050623152308.GA36909@winnie.fuhr.org
обсуждение исходный текст
Ответ на fields and foreign keys  ("mrix" <gmarik@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Corrupted index
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: plpgsql and schema