| 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-07-01 14:12:31 |
| Message-ID: | CANxoLDdVEjCCKch1O-5J6ghw89b2fkWC1ADPYTUwxu8WB-hQbw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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(dot)parragi(at)percona(dot)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 | Content-Type | Size |
|---|---|---|
| v14-0001-Add-pg_get_table_ddl-to-reconstruct-CREATE-TABLE.patch | application/octet-stream | 193.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jonathan Gonzalez V. | 2026-07-01 14:15:01 | Re: Coverage (lcov) failing with inconsistent error in versions 2.x |
| Previous Message | Antonin Houska | 2026-07-01 13:57:02 | Re: REPACK CONCURRENTLY fails on tables with generated columns |