0

I am using this query to try to get all the indexes that a table of a Postgre daabase contains but I am getting an error. What's the query to do it?

SHOW INDEXES FROM table_name
Fabio
  • 343
  • 1
  • 6
  • 17

1 Answers1

1

PostgreSQL does not provide a command like SHOW INDEXES to list the index information of a table or database.

However, it does provide you with access to the pg_indexes view so that you can query the index information.

If you use psql to access the PostgreSQL database, you can use the \d command to view the index information for a table.

You could try something like this:

SELECT
    indexname,
    indexdef
FROM
    pg_indexes
WHERE
    tablename = 'table_name';
ikos23
  • 4,879
  • 10
  • 41
  • 60
  • Does this work in a Java application? – Fabio May 17 '21 at 08:48
  • @Fabio It's just a regular SQL. I don't see any reasons why it should not work in Java World, whether you use plain JDBC or JPA-based approach (JPQL, etc.) or Spring Data, etc. – ikos23 May 17 '21 at 08:58