How to find primary keys by querying system tables

From: josteinu(at)sylfest(dot)hiof(dot)no (Jostein Ulseth)
To: pgsql-sql(at)postgresql(dot)org
Subject: How to find primary keys by querying system tables
Date: 2001-10-24 13:51:14
Message-ID: 793204a0.0110240551.645a43b@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-sql by date

  From Date Subject
Next Message guard 2001-10-24 14:56:06 Lock full database
Previous Message Dinesh Parikh 2001-10-24 05:55:59 GUID in postgres