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 4AFBED7008 for ; Mon, 22 Aug 2005 07:23:34 -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 67692-04 for ; Mon, 22 Aug 2005 10:23:31 +0000 (GMT) Received: from web51901.mail.yahoo.com (web51901.mail.yahoo.com [206.190.48.64]) by svr1.postgresql.org (Postfix) with SMTP id 0C9D7D7010 for ; Mon, 22 Aug 2005 07:23:30 -0300 (ADT) Received: (qmail 75395 invoked by uid 60001); 22 Aug 2005 10:23:29 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=FSJJqWIN1BGGCGM/UPhfOJ20VZAL3gLn6RKBSb7sWfGFVSRQwgvNWAi+5ye4j3/prD+CQ7ceAogbosrDkZ8TQAIwiQrnSdrTHFRlN7/ec5HE4VXTTOX0Q49TjSuJH5p9c1xKIfMJstPUnzr5MEDR4qfw94/mpXLaKYKwooDZ40w= ; Message-ID: <20050822102329.75393.qmail@web51901.mail.yahoo.com> Received: from [80.84.141.227] by web51901.mail.yahoo.com via HTTP; Mon, 22 Aug 2005 03:23:29 PDT Date: Mon, 22 Aug 2005 03:23:29 -0700 (PDT) From: Roger Tannous Subject: Re: A Table's Primary Key Listing To: "D'Arcy J.M. Cain" Cc: pgsql-sql@postgresql.org, tgl@sss.pgh.pa.us, roger77_lb@hotmail.com In-Reply-To: <20050818135524.74852123.darcy@druid.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.332 required=5 tests=[AWL=-0.042, DNS_FROM_RFC_ABUSE=0.374] X-Spam-Level: X-Archive-Number: 200508/181 X-Sequence-Number: 22409 So, D'Arcy's solution, although described as 'unsatisfactory' (ref.: D'Arcy's message), seem to be the only solution. So I noticed I was trying to play the wise man, trying to do things in a better way, but nothing was found than D'Arcy's query: 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_%' AND pg_class.relname like 'sip_%' 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; Regards, Roger Tannous. --- "D'Arcy J.M. Cain" wrote: > 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. > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com