X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id EB417D1B8A4 for ; Fri, 15 Aug 2003 15:57:53 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 82549-02 for ; Fri, 15 Aug 2003 12:57:42 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 5DCCFD1B898 for ; Fri, 15 Aug 2003 12:57:41 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h7FFve5H018737; Fri, 15 Aug 2003 11:57:41 -0400 (EDT) To: Tim Andersen Cc: pgsql-sql@postgresql.org Subject: Re: About primary keys. In-reply-to: <20030815143853.64952.qmail@web10009.mail.yahoo.com> References: <20030815143853.64952.qmail@web10009.mail.yahoo.com> Comments: In-reply-to Tim Andersen message dated "Fri, 15 Aug 2003 07:38:53 -0700" Date: Fri, 15 Aug 2003 11:57:40 -0400 Message-ID: <18736.1060963060@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/194 X-Sequence-Number: 14810 Tim Andersen writes: > The query I have so far only gets columns that are > part of a primary key. > ... > and pga1.attnum = i.indkey[pga2.attnum-1]; This is wrong because you are looking at only one indkey position, and the attribute could be in any position of the primary key. I think what you want is to drop pga2 from the query and instead use something like ... and pga1.attnum in (i.indkey[0], i.indkey[1], i.indkey[2], ...) (carrying it out to whatever you think is a reasonable upper bound on the number of columns in a primary key --- the normal Postgres limit is 32 keys but I can't believe anyone would use that many in practice). regards, tom lane