Skip to main content

Overview

The pg_get_indexdef() is a system catalog information function that reconstructs the PostgreSQL command used to retrieve the definition of a specified index.

Syntax

Here are the two available syntax versions of the pg_get_indexdef() function:

Parameters

The following parameters are required to execute this function:
  • index_oid: specifies the object identifier (OID) of the index
  • column_oid: indicates the column number within the index (starting from 1)
  • pretty_bool: controls whether to format the output in a human-readable way

Example

In this example we’ll start from creating a sample table and an index for it
Once that is done, we can get the OID of the index in a following way
As the last step we’re going to retrieve the index definition
Here is the reconstructed definition: