Re: relation between tables

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: relation between tables
Дата
Msg-id 20050329005018.GA17577@winnie.fuhr.org
обсуждение исходный текст
Ответ на relation between tables  (Mauricio Siqueira de Oliveira <mauricio.oliveiraa@uol.com.br>)
Ответы Re: relation between tables  (Todd Lewis <lewis-todd@sbcglobal.net>)
Список pgsql-novice
On Mon, Mar 28, 2005 at 08:30:54PM -0300, Mauricio Siqueira de Oliveira wrote:
>
> Is there any command to display relations between tables? Like, for
> instance, I would like to know what column in what table is linked with
> a particular column in other table.

In psql you can use "\d tablename" to see a table's definition,
including foreign key constraints.  If you run "psql -E" or execute
"\set ECHO_HIDDEN" then you can see the SQL queries that psql runs
to get that information, and from those queries you can figure out
how to write your own queries.  You'll probably want to be familiar
with the "System Catalogs" chapter of the documentation and the
"System Information Functions" or "Miscellaneous Functions" section
of the "Functions and Operators" chapter.

Here's an example that might show what you're looking for:

SELECT conrelid::regclass AS relname,
       conname,
       pg_get_constraintdef(oid) AS condef
FROM pg_constraint
WHERE contype = 'f'
ORDER BY conrelid, conname;

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

В списке pgsql-novice по дате отправления:

Предыдущее
От: Mauricio Siqueira de Oliveira
Дата:
Сообщение: relation between tables
Следующее
От: Todd Lewis
Дата:
Сообщение: Re: relation between tables