1postgres@db # SELECT a.attname
2FROM pg_class t
3 JOIN pg_index ix ON t.oid = ix.indrelid
4 JOIN pg_class i ON i.oid = ix.indexrelid
5 JOIN pg_attribute a ON a.attrelid = t.oid
6WHERE
7 a.attnum = ANY(ix.indkey) AND
8 t.relkind = 'r' AND
9 t.relname ='test' -- table name
10ORDER BY
11 t.relname,
12 i.relname;
13 attname
14---------
15 column1
16 column2
17 id
18(3 rows)
19