X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A96DD52C10 for ; Thu, 18 Aug 2005 14:55:26 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53635-02 for ; Thu, 18 Aug 2005 17:55:23 +0000 (GMT) Received: from ox.eicat.ca (ox.eicat.ca [66.96.30.35]) by svr1.postgresql.org (Postfix) with ESMTP id 4909D52C92 for ; Thu, 18 Aug 2005 14:55:22 -0300 (ADT) Received: from dilbert (H245.C18.B96.tor.eicat.ca [66.96.18.245]) by ox.eicat.ca (Postfix) with SMTP id 2FC84D72A; Thu, 18 Aug 2005 13:55:23 -0400 (EDT) Date: Thu, 18 Aug 2005 13:55:24 -0400 From: "D'Arcy J.M. Cain" To: Roger Tannous Cc: pgsql-sql@postgresql.org Subject: Re: A Table's Primary Key Listing Message-Id: <20050818135524.74852123.darcy@druid.net> In-Reply-To: <20050818164057.38362.qmail@web51906.mail.yahoo.com> References: <20050818121844.33a09ad2.darcy@druid.net> <20050818164057.38362.qmail@web51906.mail.yahoo.com> X-Mailer: Sylpheed version 2.0.0 (GTK+ 2.6.8; i386--netbsdelf) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200508/147 X-Sequence-Number: 22375 On Thu, 18 Aug 2005 09:40:57 -0700 (PDT) Roger Tannous wrote: > Thanks for your query :) > > But it only shows the first of the primary keys of tables having multiple > primary keys :) > > This is apparently because of the pg_index.indkey[0] thing, so how can we > manage this query in order to get all of the keys :) That's a good question. The following query does this in a very unsatisfactory way. Anyone know what the general solution would be? SELECT pg_namespace.nspname, pg_class.relname,pg_attribute.attname FROM pg_class JOIN pg_namespace ON pg_namespace.oid=pg_class.relnamespace AND pg_namespace.nspname NOT LIKE 'pg_%' JOIN pg_attribute ON pg_attribute.attrelid=pg_class.oid AND pg_attribute.attisdropped='f' JOIN pg_index ON pg_index.indrelid=pg_class.oid AND pg_index.indisprimary='t' AND ( pg_index.indkey[0]=pg_attribute.attnum OR pg_index.indkey[1]=pg_attribute.attnum OR pg_index.indkey[2]=pg_attribute.attnum OR pg_index.indkey[3]=pg_attribute.attnum OR pg_index.indkey[4]=pg_attribute.attnum OR pg_index.indkey[5]=pg_attribute.attnum OR pg_index.indkey[6]=pg_attribute.attnum OR pg_index.indkey[7]=pg_attribute.attnum OR pg_index.indkey[8]=pg_attribute.attnum OR pg_index.indkey[9]=pg_attribute.attnum ) ORDER BY pg_namespace.nspname, pg_class.relname,pg_attribute.attname; -- D'Arcy J.M. Cain | 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.