Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements - Mailing list pgsql-hackers

From Marcos Pegoraro
Subject Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Date
Msg-id CAB-JLwbyzF+JRPCoLCf-H6dQ_1+-O_wBZcESRdC6_H2z+-d-gg@mail.gmail.com
Whole thread
In response to Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements  (Akshay Joshi <akshay.joshi@enterprisedb.com>)
List pgsql-hackers
Em seg., 15 de jun. de 2026 às 04:52, Akshay Joshi <akshay.joshi@enterprisedb.com> escreveu:
I don't think per-contype flags are the right shape, though. The existing toggles group by catalog (indexes, constraints, rules, ...); splitting constraints into PK/FK/CHECK/UNIQUE/EXCLUDE/NOT NULL adds six flags on a second axis, and the function already carries nine. Only FKs have the cross-table dependency-ordering problem; the rest only reference the same table, so splitting them unlocks nothing new.

Ok, I understand your point. Initially, I saw the usefulness of this function for cloning a schema, something very common in a multi-tenant model. But creating the foreign keys along with the create table makes that unfeasible.

Options are variadic, so you could split your emit_local_constraints into 
+emit_local_foreign_keys_constraints(TableDdlContext * ctx) 
+ if (!(ctx->include_constraints || ctx->include_foreign_keys)) then
+   return

+emit_local_primary_keys_constraints(TableDdlContext * ctx) 
+ if (!(ctx->include_constraints || ctx->include_primary_keys)) then
+   return

pg_get_table_ddl('x','includes_constraints','true') -- would print all constraints
pg_get_table_ddl('x','include_primary_keys','true') -- would print only primary key constraints

regards
Marcos

pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Adding a stored generated column without long-lived locks
Next
From: Zsolt Parragi
Date:
Subject: Re: [PATCH v2] Add ssl_alt_cert_file/ssl_alt_key_file for dual RSA+ECDSA certificate support