| From: | darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain) |
|---|---|
| To: | David BOURIAUD <david(dot)bouriaud(at)ac-rouen(dot)fr> |
| Cc: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: About primary keys. |
| Date: | 2001-06-19 12:36:25 |
| Message-ID: | 20010619123625.F01A21A78@druid.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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.attrelid AND
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(at){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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David BOURIAUD | 2001-06-19 12:50:22 | Re: About primary keys. |
| Previous Message | David BOURIAUD | 2001-06-19 12:10:16 | About primary keys. |