I think : regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
should be : generate_series(1, array_length(indkey,1))::smallint AS attnum,
the join with pg_attributes include attnum but pg_attributes will number the attributes for the index at 1. the pg_index indkey is the physical index to the column within the table.
thanks for this query. its very helpful.