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

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Akshay Joshi <akshay(dot)joshi(at)enterprisedb(dot)com>
Cc: Rui Zhao <zhaorui126(at)gmail(dot)com>, 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-07-11 19:22:36
Message-ID: CAB-JLwae7bWN_hTtzFqqk5=g1OFp5MwtL34KY7EfcUVBv8EQFw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em qui., 9 de jul. de 2026 às 05:54, Akshay Joshi <
akshay(dot)joshi(at)enterprisedb(dot)com> escreveu:

> Fixed the documentation. v19 patch is now ready for review.
>

I didn't understand when a word is considered reserved, so that it has
double quotes.

postgres=# create table int(int4 integer primary key, integer integer,
interval interval, boolean boolean, insert boolean);
CREATE TABLE
postgres=# select pg_get_table_ddl('int'::regclass,
schema_qualified=>false, owner=>true, only_kinds =>
ARRAY['primary_key','check','table']);
pg_get_table_ddl
------------------------------------------------------------------------------------------------------------------------
CREATE TABLE "int" (int4 integer NOT NULL, "integer" integer, "interval"
interval, "boolean" boolean, insert boolean);
ALTER TABLE "int" OWNER TO postgres;
ALTER TABLE "int" ADD CONSTRAINT int_pkey PRIMARY KEY (int4);
(3 rows)

And as for the owner, I think that causes a bit of confusion when used with
kinds parameters, doesn't it ?
It emits other ALTER TABLE except the OWNER TO.

postgres=# create table self(id integer primary key, self_id integer
constraint self_self references self(id));
CREATE TABLE
postgres=# select pg_get_table_ddl('self'::regclass, owner=>true,
except_kinds => ARRAY['table']);
pg_get_table_ddl
--------------------------------------------------------------------------------------------------
ALTER TABLE public.self ADD CONSTRAINT self_pkey PRIMARY KEY (id);
ALTER TABLE public.self ADD CONSTRAINT self_self FOREIGN KEY (self_id)
REFERENCES public.self(id);
(2 rows)
regards
Marcos

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2026-07-11 19:30:18 Re: SQL/JSON json_table plan clause
Previous Message Dmitry Fomin 2026-07-11 18:42:08 Re: [PATCH v1 0/7] Wait event timing and tracing instrumentation