Re: Find out foreign key - Mailing list pgsql-admin

From Chris Mair
Subject Re: Find out foreign key
Date
Msg-id 1155236961.5893.43.camel@dell.home.lan
Whole thread Raw
In response to Find out foreign key  (Alexander Burbello <alexander@cresoltec.com.br>)
List pgsql-admin
> Hi people,
>
> I would like to know what's the system view that has information about
> parent table and child table associated by Foreign Key!!
>
> Is it possible to find out that information?
>
> Thank you.

Here you go (tested on 8.1) :)

SELECT c.relname as table, r.conname as contraint,
pg_catalog.pg_get_constraintdef(r.oid, true) as constraint_definition
FROM pg_catalog.pg_constraint r, pg_catalog.pg_class c WHERE c.oid =
r.conrelid AND r.contype = 'f';

Bye,
Chris.


--

Chris Mair
http://www.1006.org



pgsql-admin by date:

Previous
From: Steve Crawford
Date:
Subject: Re: pg_dump from crontab
Next
From: Tom Lane
Date:
Subject: Re: data for 64bits on 32