1

How can I learn which operator class is used by an already created index in PostgreSQL?

0

1 Answer 1

3

You can query the system catalog.
There can be multiple operator classes for multi-column indexes.

SELECT opcname
FROM  (
   SELECT unnest(indclass) AS ind_op
   FROM   pg_index
   WHERE  indexrelid = 'index_schema.index_name'::regclass
   ) i 
JOIN   pg_opclass o ON o.oid = i.ind_op;

indclass is of type oidvector which can be unnested like any array. This way, you get multiple lines for a multi-column index. More details about the catalog tables in the manual here and here.

If index_schema is in your search_path (and comes first, in case of duplicate index names), you don't have to schema-qualify the name.

Sign up to request clarification or add additional context in comments.

2 Comments

More most case, I think the index_schema is 'public',
@zw963: In simple cases, yes. But the index lives in the same schema as its parent table, which can be most any schema, especially in multi-user environments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.