Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5JEdJa09773 for ; Tue, 19 Jun 2001 10:39:19 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f5JEck322744; Tue, 19 Jun 2001 10:38:46 -0400 (EDT) To: David BOURIAUD cc: "pgsql-sql@postgresql.org" Subject: Re: About primary keys. In-reply-to: <3B2F4A8E.B6E07DBB@ac-rouen.fr> References: <20010619123625.F01A21A78@druid.net> <3B2F4A8E.B6E07DBB@ac-rouen.fr> Comments: In-reply-to David BOURIAUD message dated "Tue, 19 Jun 2001 14:50:22 +0200" Date: Tue, 19 Jun 2001 10:38:45 -0400 Message-ID: <22741.992961525@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200106/291 X-Sequence-Number: 3554 David BOURIAUD writes: >> Caveat: Does not work for complex primary keys. > Thanks, but that is my problem actually ! Here's a rather brute-force approach: select relname, (select attname from pg_attribute where attrelid = c.oid and attnum = indkey[0]), (select attname from pg_attribute where attrelid = c.oid and attnum = indkey[1]), (select attname from pg_attribute where attrelid = c.oid and attnum = indkey[2]), (select attname from pg_attribute where attrelid = c.oid and attnum = indkey[3]) from pg_class c, pg_index i where c.oid = indrelid and indisprimary; You can carry this out to however many key columns you want to deal with. The sub-selects will yield NULLs for the columns after the last key column of a particular index, which is just what you want here. regards, tom lane