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

From: Noura Elhawary <nelhawar(at)redhat(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: what is the best way to get key information in postgres?
Date: 2007-03-01 00:48:17
Message-ID: 1172710097.3531.39.camel@scarecrow.brisbane.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2007-03-01 01:19:52 Re: Esay question, about the numeric format
Previous Message Bricklen Anderson 2007-02-28 23:05:08 Re: pg_dump inquiry