Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Akshay Joshi <akshay(dot)joshi(at)enterprisedb(dot)com>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Date: 2026-06-15 21:04:43
Message-ID: CAB-JLwbyzF+JRPCoLCf-H6dQ_1+-O_wBZcESRdC6_H2z+-d-gg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em seg., 15 de jun. de 2026 às 04:52, Akshay Joshi <
akshay(dot)joshi(at)enterprisedb(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-06-15 21:13:29 Re: [PATCH v2] Add ssl_alt_cert_file/ssl_alt_key_file for dual RSA+ECDSA certificate support
Previous Message Alexander Korotkov 2026-06-15 20:50:07 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands