Get DDL (CREATE statement) for a Database Object
pg_get_ddlRetrieve the DDL (CREATE statement) for any PostgreSQL table, view, materialized view, function, or index. Generate SQL code to replicate object definitions across environments.
Instructions
Get the CREATE statement (DDL) for a table, view, materialized view, function, or index.
Args:
object_name: Name of the object (required)
schema: Schema name (default: public)
object_type: Type of object: 'table', 'view', 'matview', 'function', 'index' (default: 'table')
Returns: JSON: { schema, object_name, object_type, ddl: string } Markdown: formatted SQL code block
Useful for understanding table structure, reproducing objects in other environments, or code review.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| object_name | Yes | Name of the object | |
| schema | No | PostgreSQL schema name (default: public) | public |
| object_type | No | Object type: 'table', 'view', 'matview', 'function', 'index' | table |