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

From: Akshay Joshi <akshay(dot)joshi(at)enterprisedb(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements
Date: 2026-06-15 07:52:03
Message-ID: CANxoLDdRts-F+QxL+wtM8529Z3+TUJku8PKy3WoxcWBs7zQJ-w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 11, 2026 at 6:38 PM Marcos Pegoraro <marcos(at)f10(dot)com(dot)br> wrote:

> Em qui., 11 de jun. de 2026 às 04:48, Akshay Joshi <
> akshay(dot)joshi(at)enterprisedb(dot)com> escreveu:
>
>> Fixed the issue above. The v5 patch is ready for review/testing.
>>
>
> One thing I noticed, though I'm not sure if it's the point here, is that
> it's not possible to extract only the foreign keys or only the triggers
> from the table. So if we want to extract the objects independently by type,
> we would need to have all the return types as optional, and we could have
> more granularity in the return types.
>
> Just like you have...
> if (!ctx->include_indexes)
>
> You could have too
> + if (!ctx->include_create_table)
> + if (!ctx->include_foreign_keys)
> + if (!ctx->include_primary_keys)
>
> Because only in this way can we more or less execute the dump behavior
> here, which is to create all the tables beforehand, then primary keys, then
> foreign keys, then triggers.
>
> I repeat, sorry if this is not the function's intended purpose.
>

I don't think per-contype flags are the right shape, though. The existing
toggles group by catalog (indexes, constraints, rules, ...); splitting
constraints into PK/FK/CHECK/UNIQUE/EXCLUDE/NOT NULL adds six flags on a
second axis, and the function already carries nine. Only FKs have the
cross-table dependency-ordering problem; the rest only reference the same
table, so splitting them unlocks nothing new.

On include_create_table, we are reconstructing the DDL for the table
itself, so I don't think we should skip the CREATE TABLE statement. I'd
rather always emit CREATE TABLE.

> regards
> Marcos
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2026-06-15 07:55:48 Re: pg_restore handles extended statistics inconsistently with statistics data
Previous Message Kyotaro Horiguchi 2026-06-15 07:39:22 Re: [PATCH] Change wait_time column of pg_stat_lock to double precision