David BOURIAUD <david.bouriaud@ac-rouen.fr> 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_attributewhere 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