How to find primary keys by querying system tables - Mailing list pgsql-sql

From josteinu@sylfest.hiof.no (Jostein Ulseth)
Subject How to find primary keys by querying system tables
Date
Msg-id 793204a0.0110240551.645a43b@posting.google.com
Whole thread Raw
List pgsql-sql
Hi. 

I'm trying to write a select statement that does the following; 
select all tables in my database; 
for each table, select all columns, and tell me if the column is a
primary key
in the table. 

I've tried this by querying pg_class, pg_index and pg_attribute, but I
have a problem when I this is supposed to be "general", ie I do not
know the maximum number of columns in a primary key (I can't use
subscription of "indkey").

Is there a way of testing for membership in an int2vector-field? For
example:
select column, "prim.key" from ... where pg_attribute.attnum in
pg_index.indkey
?? 

Thanks! 

-Jostein


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Cross-posting (was Re: GUID in postgres)
Next
From: John Hasler
Date:
Subject: Re: GUID in postgres