List columns with indexes in PostgreSQL

后端 未结 23 2003
我在风中等你
我在风中等你 2020-11-27 09:14

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

23条回答
  •  没有蜡笔的小新
    2020-11-27 09:57

    Just do: \d table_name

    But I'm not sure what do you mean that the information about columns is not there.

    For example:

    # \d pg_class
           Table "pg_catalog.pg_class"
         Column      |   Type    | Modifiers
    -----------------+-----------+-----------
     relname         | name      | not null
     relnamespace    | oid       | not null
     reltype         | oid       | not null
     reloftype       | oid       | not null
     relowner        | oid       | not null
     relam           | oid       | not null
     relfilenode     | oid       | not null
     reltablespace   | oid       | not null
     relpages        | integer   | not null
     reltuples       | real      | not null
     reltoastrelid   | oid       | not null
     reltoastidxid   | oid       | not null
     relhasindex     | boolean   | not null
     relisshared     | boolean   | not null
     relistemp       | boolean   | not null
     relkind         | "char"    | not null
     relnatts        | smallint  | not null
     relchecks       | smallint  | not null
     relhasoids      | boolean   | not null
     relhaspkey      | boolean   | not null
     relhasexclusion | boolean   | not null
     relhasrules     | boolean   | not null
     relhastriggers  | boolean   | not null
     relhassubclass  | boolean   | not null
     relfrozenxid    | xid       | not null
     relacl          | aclitem[] |
     reloptions      | text[]    |
    Indexes:
        "pg_class_oid_index" UNIQUE, btree (oid)
        "pg_class_relname_nsp_index" UNIQUE, btree (relname, relnamespace)
    

    It clearly shows which columns given index is on this table.

提交回复
热议问题