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

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Date: 2026-06-23 20:05:20
Message-ID: CAN4CZFPKAr2VfxGMTA4CkMPHVSnpQrRKJcwUH1ZLh4eHG09LSw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2026-06-23 20:06:13 Re: Problems with get_actual_variable_range's VISITED_PAGES_LIMIT
Previous Message Andrew Dunstan 2026-06-23 19:17:52 Re: Fix variadic argument types for pg_get_xxx_ddl() functions