Re: Find out foreign key

From: Chris Mair <chrisnospam(at)1006(dot)org>
To: Alexander Burbello <alexander(at)cresoltec(dot)com(dot)br>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Find out foreign key
Date: 2006-08-10 19:09:21
Message-ID: 1155236961.5893.43.camel@dell.home.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2006-08-10 23:10:39 Re: data for 64bits on 32
Previous Message Steve Crawford 2006-08-10 19:04:25 Re: pg_dump from crontab