GET TABLE METADATA

This feature is designed for Model Context Protocol (MCP) servers and database users who need metadata details.

Returns complete Apache Iceberg table metadata, including schema, partition specifications, and sort orders. This feature is designed for database users who need detailed Iceberg metadata but do not have easy access to the underlying storage where metadata files reside. It also supports Model Context Protocol (MCP) servers that require a SQL interface to retrieve this information for decision-making.

The GET_TABLE_METADATA function accepts the name of an external Iceberg table and returns the contents of its latest metadata JSON file as a single string. The metadata includes comprehensive information about the table structure and configuration, making it easier to integrate with external systems and perform analysis.

Syntax

GET_TABLE_METADATA ('external_iceberg_table_name')

Parameter

external_iceberg_table_name
The name of the external Iceberg table for which you want to retrieve metadata. The table must already be created in the database. Returns a single VARCHAR string containing the full contents of the latest Iceberg metadata JSON file.

Examples

Create an external Iceberg table and retrieve its metadata.

=> CREATE EXTERNAL TABLE ice_t
   STORED BY ICEBERG LOCATION 's3://sales/iceberg_s3_glue'
   GLUE_DB 'my_glue_db'
   GLUE_TABLE 'my_glue_table';
=> SELECT GET_TABLE_METADATA('ice_t');

Output

get_table_metadata
--------------------------------------------------------------------------------------------------------
{
    "format-version": 2,
    "table-uuid": "42ab7c57-fe4f-4f25-ae62-bb92e17257f1",
    "location": "s3://sales/iceberg_s3_glue/",
    "last-sequence-number": 1,
    "last-updated-ms": 1765208339000,
    "last-column-id": 3,
    "last-partition-id": 0,
    "schemas": [
        {
            "schema-id": 0,
            "type": "struct",
            "fields": [
                {"id": 0, "name": "a", "required": false, "type": "long"},
                {"id": 1, "name": "b", "required": false, "type": "long"},
                {"id": 2, "name": "c", "required": false, "type": "string"},
                {"id": 3, "name": "d", "required": false, "type": "double"}
            ]
        }
    ],
    "current-schema-id": 0,
    "partition-specs": [{"spec-id": 0, "fields": []}],
    "default-spec-id": 0,
    "sort-orders": [{"order-id": 0, "fields": []}],
    "default-sort-order-id": 0,
    "snapshots": [
        {
            "snapshot-id": 4860869929048570211,
            "sequence-number": 1,
            "timestamp-ms": 1765208339000,
            "manifest-list": "s3://sales/iceberg_s3_glue/metadata/manifest-list.avro",
            "summary": {"operation": "append", "added-data-files": "15"}
        }
    ],
    "current-snapshot-id": 4860869929048570211,
    "refs": {"main": {"snapshot-id": 4860869929048570211, "type": "branch"}}
}
(1 row)