Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f9OE5oP34165 for ; Wed, 24 Oct 2001 10:05:50 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f9ODpKI77539 for pgsql-sql@postgresql.org; Wed, 24 Oct 2001 09:51:20 -0400 (EDT) (envelope-from news) From: josteinu@sylfest.hiof.no (Jostein Ulseth) X-Newsgroups: comp.databases.postgresql.sql Subject: How to find primary keys by querying system tables Date: 24 Oct 2001 06:51:14 -0700 Organization: http://groups.google.com/ Lines: 22 Message-ID: <793204a0.0110240551.645a43b@posting.google.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org X-Archive-Number: 200110/347 X-Sequence-Number: 5300 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