Skip to content
Advertisement

List columns with indexes in PostgreSQL

I would like to get the columns that an index is on in PostgreSQL.

In MySQL you can use SHOW INDEXES FOR table and look at the Column_name column.

Does anything like this exist for PostgreSQL?

I’ve tried d at the psql command prompt (with the -E option to show SQL) but it doesn’t show the information I’m looking for.

Update: Thanks to everyone who added their answers. cope360 gave me exactly what I was looking for, but several people chimed in with very useful links. For future reference, check out the documentation for pg_index (via Milen A. Radev) and the very useful article Extracting META information from PostgreSQL (via Michał Niklas).

Advertisement

Answer

Create some test data…

List indexes and columns indexed:

Roll up the column names:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement