ddlx
ddlx
pg_ddlx : DDL eXtractor functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 5080 | ddlx | pg_ddlx | 0.30 | ADMIN | PostgreSQL | SQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | pgdd pg_checksums pg_permissions pgextwlist pg_catcheck adminpack pg_repack pg_rewrite |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.30 | 18 17 16 15 14 | pg_ddlx | - |
| RPM | PIGSTY | 0.30 | 18 17 16 15 14 | ddlx_$v | - |
| DEB | PIGSTY | 0.30 | 18 17 16 15 14 | postgresql-$v-ddlx | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
el8.aarch64 | PGDG 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
el9.x86_64 | PGDG 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
el9.aarch64 | PGDG 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
el10.x86_64 | PGDG 0.30 | PGDG 0.30 | PGDG 0.30 | PGDG 0.30 | PGDG 0.30 |
el10.aarch64 | PGDG 0.30 | PGDG 0.30 | PGDG 0.30 | PGDG 0.30 | PGDG 0.30 |
d12.x86_64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
d12.aarch64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
d13.x86_64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
d13.aarch64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
u22.x86_64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
u22.aarch64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
u24.x86_64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
u24.aarch64 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 | PIGSTY 0.30 |
Source
pig build pkg pg_ddlx; # build debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_ddlx; # install via package name, for the active PG version
pig install ddlx; # install by extension name, for the current active PG version
pig install ddlx -v 18; # install for PG 18
pig install ddlx -v 17; # install for PG 17
pig install ddlx -v 16; # install for PG 16
pig install ddlx -v 15; # install for PG 15
pig install ddlx -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION ddlx;Usage
ddlx is a SQL-only extension that generates DDL scripts from PostgreSQL system catalogs. It provides three main functions that accept an OID and work with all reg* object identifier types.
Core Functions
-- Generate CREATE statement for an object
SELECT ddlx_create('my_table'::regclass);
SELECT ddlx_create('my_type'::regtype);
SELECT ddlx_create('my_function'::regproc);
SELECT ddlx_create(current_role::regrole);
-- Generate DROP statement
SELECT ddlx_drop('my_table'::regclass);
-- Generate full DDL script with dependency tree
SELECT ddlx_script('my_table'::regclass);
SELECT ddlx_script('my_enum');
SELECT ddlx_script(current_role::regrole);Options
Options are passed as a text array (e.g., '{ine,nodcl}'):
SELECT ddlx_create('my_table'::regclass, '{ine}'); -- add IF NOT EXISTS
SELECT ddlx_create('my_type'::regtype, '{noowner}'); -- omit ALTER SET OWNER
SELECT ddlx_script('my_table'::regclass, '{drop}'); -- include DROP statementsAvailable options: drop, nodrop, owner, noowner, nogrants, nodcl, noalter, ine (IF NOT EXISTS), ie (IF EXISTS), ext, lite, nowrap, nopartitions, comments, nocomments, nostorage, noconstraints, noindexes, nosettings, notriggers, grantor, data.
For Objects Without reg* Types
SELECT ddlx_create(oid) FROM pg_foreign_data_wrapper WHERE fdwname = 'postgres_fdw';
SELECT ddlx_create(oid) FROM pg_database WHERE datname = current_database();Additional Functions
-- Identify any object by OID
SELECT * FROM ddlx_identify(oid);
-- Describe columns of a class
SELECT * FROM ddlx_describe('my_table'::regclass);
-- Get individual definition parts
SELECT * FROM ddlx_definitions(oid);
-- Generate pre-data creation statements only
SELECT ddlx_createonly('my_table'::regclass);
-- Generate post-data alteration statements
SELECT ddlx_alter('my_table'::regclass);
-- Search function/view bodies by regex
SELECT ddlx_create(objid) FROM ddlx_apropos('users');
-- Get GRANT statements
SELECT ddlx_grants('my_table'::regclass);Last updated on