Problem: I have a table of the customer below, and I want to list column with indexes in PostgreSQL, Basically purpose of this question is an analysis of the performance.
CREATETABLECustomer ( IdserialNOTNULL, FNametextCOLLATEpg_catalog.default, LNametextCOLLATEpg_catalog.default, UserNametextCOLLATEpg_catalog.default, PasswordtextCOLLATEpg_catalog.default, ContacttextCOLLATEpg_catalog.default, AddresstextCOLLATEpg_catalog.default, CONSTRAINTpk_Customer_IdPRIMARYKEY (Id) ) |
Solution: Using pg_index we can list the column with index
select t.relnameastable, i.relnameasindex, a.attnameascolumn from pg_classt, pg_classi, pg_indexix, pg_attributea where t.oid=ix.indrelid andi.oid=ix.indexrelid anda.attrelid=t.oid anda.attnum=ANY(ix.indkey) andt.relkind='r' andt.relnamelike'Customer%' orderby t.relname, i.relname; |
Note: But it will not show the column on which the index is created. Also, it will show all indexes, but not for a particular table.