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

From: Akshay Joshi <akshay(dot)joshi(at)enterprisedb(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Date: 2026-06-24 09:16:03
Message-ID: CANxoLDe308ogjUZD4DLjaMysJzHZ4z3SOXbUTyC7SAEKvSgqcw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jun 24, 2026 at 1:35 AM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
wrote:

> The new design is definitely an improvement as a more generic
> interface. I'm unsure about the "include" wording, to me that suggest
> "also includes", while the actual behavior is "only includes". To me
> it would be a bit surprising pg_get_table_ddl including something not
> including the basic create table statement.
>
> I also found a few issues with include in v10.
>
> Include check doesn't seem to work:
>
> CREATE TABLE t (
> id int PRIMARY KEY,
> qty int CHECK (qty > 0),
> CONSTRAINT t_id_pos CHECK (id > 0)
> );
>
> SELECT * FROM pg_get_table_ddl('t', 'include', 'check'); -- empty?
>
> The include partitions clause also doesn't work:
>
> CREATE TABLE p (id int, val text) PARTITION BY RANGE (id);
> CREATE TABLE p_a PARTITION OF p FOR VALUES FROM (0) TO (100);
> CREATE TABLE p_b PARTITION OF p FOR VALUES FROM (100) TO (200);
>
> SELECT * FROM pg_get_table_ddl('p','include','partitions'); -- empty
>
> There's also an issue with replica identity non primary key unique indexes:
>
> CREATE TABLE t2 (a int NOT NULL UNIQUE, b int);
> ALTER TABLE t2 REPLICA IDENTITY USING INDEX t2_a_key;
> SELECT * FROM pg_get_table_ddl('t2','exclude','unique');
> -- ALTER TABLE public.t2 REPLICA IDENTITY USING INDEX t2_a_key;
> -- but there's no such index
>
> Thanks for the review. In the attached patch, I’ve renamed
*include/exclude* to *only* and *except*. If you have any other suggestions
or a better name, please let me know.
Fixed all the above issues as well.

The semantics remain unchanged:
1) only => 'kind1,kind2,...' — emits only the listed kinds.
2) except => 'kind1,kind2,...' — emits everything except the listed kinds.
3) Setting both raises an error; setting neither emits all kinds (the
default).

I also dropped the trailing "s" from the multi-item kind names so the
vocabulary reads naturally with only/except (e.g., index, foreign_key,
rule, trigger, policy, partition). statistics and rls retain their existing
spellings. The documentation, regression tests, and func-info.sgml have all
been updated accordingly.

The v11 patch is now ready for review and testing.

Attachment Content-Type Size
v11-0001-Add-pg_get_table_ddl-to-reconstruct-CREATE-TABLE.patch application/octet-stream 178.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Tiwari 2026-06-24 09:29:02 Re: Small patch to improve safety of utf8_to_unicode().
Previous Message Daniel Gustafsson 2026-06-24 09:11:08 Re: Little checksum worker cleanups