Re: About primary keys. - Mailing list pgsql-sql

From darcy@druid.net (D'Arcy J.M. Cain)
Subject Re: About primary keys.
Date
Msg-id 20010619123625.F01A21A78@druid.net
Whole thread Raw
In response to About primary keys.  (David BOURIAUD <david.bouriaud@ac-rouen.fr>)
List pgsql-sql
Thus spake David BOURIAUD
> Is there a way to get in system tables all the primary keys of a table ?
> Thanks by advance.

SELECT pg_class.relname, pg_attribute.attname   FROM pg_class, pg_attribute, pg_index   WHERE pg_class.oid =
pg_attribute.attrelidAND       pg_class.oid = pg_index.indrelid AND       pg_index.indkey[0] = pg_attribute.attnum AND
    pg_index.indisprimary = 't'
 

Caveat:  Does not work for complex primary keys.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.


pgsql-sql by date:

Previous
From: David BOURIAUD
Date:
Subject: About primary keys.
Next
From: David BOURIAUD
Date:
Subject: Re: About primary keys.