# pg_get_indexdef

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: pg_get_indexdef
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/other-functions/pg-get-indexdef
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/other-functions/pg-get-indexdef.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/other-functions/pg-get-indexdef.adoc
description: The pg_get_indexdef() function reconstructs the PostgreSQL command used to retrieve the definition of a specified index.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/other-functions/pg-get-indexdef.md -->

The [`pg_get_indexdef()`](https://www.postgresql.org/docs/current/functions-info.html#FUNCTIONS-INFO-CATALOG) is a system catalog information function that reconstructs the PostgreSQL command used to retrieve the definition of a specified index.

## [](#syntax)Syntax

The `pg_get_indexdef()` function has three available syntax versions:

```sql
pg_get_indexdef(index_oid)
```

```sql
pg_get_indexdef(index_oid, column_oid)
```

```sql
pg_get_indexdef(index_oid, column_oid, pretty_bool)
```

## [](#parameters)Parameters

The parameters 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.


## [](#examples)Examples

Create a sample table and an index for it:

```sql
CREATE TABLE sample_table(col int);
CREATE INDEX sample_index ON sample_table(col);
```

Once that is done, get the OID of the index:

```sql
SELECT oid FROM pg_class WHERE relname = 'sample_index';
```

```sql
 oid
------
 16387
```

Retrieve the index definition:

```sql
SELECT pg_get_indexdef(16387);
```

The query returns the reconstructed definition:

```sql
                    pg_get_indexdef
-------------------------------------------------------
 CREATE INDEX sample_index ON public.sample_table(col)
(1 row)
```