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

what is the best way to get key information in postgres?



Hi,

I want to know what is the best way to get all the keys(unique, primary,
foreign, multiple) for a table in postgres, I actually found this query
and i am not sure if it is the best way to get the keys info:

select r.relname as "Table", c.conname as "Constraint Name", contype as
"Constraint Type", conkey as "Key Columns", confkey as "Foreign
Columns", consrc as "Source" from pg_class r, pg_constraint c where
r.oid=c.conrelid and relname='tablename';


And if the above query is good, how can I display in the output the
column names that relates to the key.

Can I use that query to get The multiple key info? or what is the best
way to do so?


I will really appreciate your help.

Thanks, 

Noura Elhawary





Home | Main Index | Thread Index

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