Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Find out foreign key



> 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





Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group