Comma separated list of PK attributes

select
relation,
max
(case when conseq=1 then attname else null end) ||
max
(case when conseq=2 then ‘,’||attname else ” end) ||
max
(case when conseq=3 then ‘,’||attname else ” end) ||
max
(case when conseq=4 then ‘,’||attname else ” end)
cn
from
_v_relation_keydata
where
contype=’p’
group
by relation,constraintname
order
by relation