| 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-19 19:45:12 |
| Message-ID: | CAN4CZFM99cGopPJXD_t05+Y9CnocOOTipfXCzoAfBUFSC-i4+A@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
The previous features all look good to me, I only have one question
for the new flag.
> Calling
> pg_get_table_ddl(t, 'includes_foreign_keys', 'false') now emits everything
> except FOREIGN KEY constraints. This covers the multi-tenant clone
> workflow: create tables first without cross-table references, then re-run
> with the default to add the constraints once all targets exist.
I think this feature needs a bit more documentation, an
"only_foreign_keys" flag, or both.
CREATE TABLE refd (id int PRIMARY KEY);
CREATE TABLE cons (a int CHECK(a>0), b int UNIQUE, c int REFERENCES refd(id));
-- pass 1: running without foreign keys
SELECT * FROM pg_get_table_ddl('cons','includes_foreign_keys','false');
-- execute everything
-- loading data
-- pass 2: running with everything
SELECT * FROM pg_get_table_ddl('cons','includes_foreign_keys','true');
-- ERROR: relation "cons" already exists (and the unique constraint
also collides)
I could do a "grep FOREIGN KEY" before executing (unless it's a tricky
schema where that phrase appears elsewhere), or since psql continues
on error, it will simply work if I accept a significant error noise,
but then the documentation should be clear about this limitation.
Following the documented approach and getting a bunch of unexpected
errors could be confusing for users.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G. Johnston | 2026-06-19 20:02:08 | Re: Fix \crosstabview to honor \pset display_true/display_false |
| Previous Message | dinesh salve | 2026-06-19 19:04:43 | Re: explain plans for foreign servers |