Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 555BA9FBE15 for ; Wed, 28 Feb 2007 20:54:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 50424-02 for ; Wed, 28 Feb 2007 20:54:30 -0400 (AST) X-Greylist: delayed 00:09:42.922511 by SQLgrey-1.7.4 Received: from mx1.redhat.com (mx1.redhat.com [66.187.233.31]) by postgresql.org (Postfix) with ESMTP id 959019FBE01 for ; Wed, 28 Feb 2007 20:54:40 -0400 (AST) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l210iuwM006451 for ; Wed, 28 Feb 2007 19:44:56 -0500 Received: from pobox.brisbane.redhat.com (pobox.brisbane.redhat.com [172.16.44.10]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l210isfN010845 for ; Wed, 28 Feb 2007 19:44:55 -0500 Received: from [172.16.44.139] (scarecrow.brisbane.redhat.com [172.16.44.139]) by pobox.brisbane.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id l210irB0003665 for ; Thu, 1 Mar 2007 10:44:53 +1000 Subject: what is the best way to get key information in postgres? From: Noura Elhawary To: pgsql-sql@postgresql.org Content-Type: text/plain Date: Thu, 01 Mar 2007 10:48:17 +1000 Message-Id: <1172710097.3531.39.camel@scarecrow.brisbane.redhat.com> Mime-Version: 1.0 X-Mailer: Evolution 2.8.0 (2.8.0-33.el5) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/302 X-Sequence-Number: 27636 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