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

From Akshay Joshi
Subject Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Date
Msg-id CANxoLDdVEjCCKch1O-5J6ghw89b2fkWC1ADPYTUwxu8WB-hQbw@mail.gmail.com
Whole thread
Responses Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
List pgsql-hackers
 Thanks for the continued review. I've rebased and updated the patch.
  
Andrew's commit replaced the VARIADIC text[] option interface on pg_get_role_ddl(), pg_get_tablespace_ddl(), and pg_get_database_ddl() with typed named boolean parameters. pg_get_table_ddl() now follows the exact same convention: pretty, owner, tablespace, and schema_qualified are plain boolean parameters with DEFAULT values, using PG_GETARG_BOOL() directly rather than parse_ddl_options().  The shared DdlOptType / DdlOption / parse_ddl_options infrastructure is gone entirely.

Filtering parameters: only_kinds / except_kinds as text[] 
Based on review feedback the filtering parameters(include/exclude) have been revised:
The two mutually-exclusive filter arguments are now named only_kinds and except_kinds (matching the SQL set-operation vocabulary) and take text[] rather than a comma-separated text value (e.g. only_kinds => ARRAY['index','foreign_key']).  This provides type safety and allows named-argument syntax. 

Note: only and except are the keywords, and I couldn't find any better name. Suggestions are welcome. 

The v14 patch is ready for review/test.

On Tue, Jun 30, 2026 at 3:01 AM Zsolt Parragi <zsolt.parragi@percona.com> wrote:
Hello

I noticed that there's an inconsistency with schema qualification, if
the schema is in the search path:

CREATE SCHEMA s;
CREATE TABLE s.parent (id int PRIMARY KEY);
CREATE TABLE s.t (id int PRIMARY KEY, pid int REFERENCES s.parent(id),
name text);
CREATE INDEX t_name_idx ON s.t (name);
CREATE STATISTICS s.t_stat ON id, pid FROM s.t;
SET search_path = s, public;
SELECT pg_get_table_ddl('s.t', 'owner', 'false');

outputs:

CREATE TABLE s.t (id integer NOT NULL, pid integer, name text);
CREATE INDEX t_name_idx ON t USING btree (name); -- should be s.t
ALTER TABLE s.t ADD CONSTRAINT t_pid_fkey FOREIGN KEY (pid) REFERENCES
parent(id); -- should be s.parent
ALTER TABLE s.t ADD CONSTRAINT t_pkey PRIMARY KEY (id);
CREATE STATISTICS t_stat ON id, pid FROM t; -- should be s.t


In the included testcase:

+drop cascades to view v
+drop cascades to sequence s
+ERROR:  relation "parted_range_1" already exists
+CONTEXT:  SQL statement "CREATE TABLE pgtbl_ddl_test.parted_range_1
PARTITION OF pgtbl_ddl_test.parted_range FOR VALUES FROM (0) TO
(100);"
+PL/pgSQL function inline_code_block line 22 at EXECUTE

is this error expected, doesn't it break the test?


Attachment

pgsql-hackers by date:

Previous
From: Antonin Houska
Date:
Subject: Re: REPACK CONCURRENTLY fails on tables with generated columns
Next
From: "Jonathan Gonzalez V."
Date:
Subject: Re: Coverage (lcov) failing with inconsistent error in versions 2.x