On Sun, Jul 12, 2026 at 12:53 AM Marcos Pegoraro <[email protected]> wrote:

> Em qui., 9 de jul. de 2026 às 05:54, Akshay Joshi <
> [email protected]> 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
>

*On quoting*: This is correct behavior, not a bug. quote_identifier quotes
any identifier whose keyword category is not UNRESERVED_KEYWORD. insert is
UNRESERVED_KEYWORD in PostgreSQL's grammar (it can be used as an identifier
without quoting), while integer, interval, and boolean are COL_NAME_KEYWORD
— they can only serve as column names in restricted contexts, so they need
quoting when used as general identifiers. The table name "int" is quoted
for the same reason (int is COL_NAME_KEYWORD). This is identical to what
pg_dump and quote_identifier do throughout PostgreSQL.


*On owner + except_kinds*: Also correct behavior by design. The owner
parameter controls whether the ALTER TABLE ... OWNER TO statement is
included when the table kind is in scope. OWNER TO is grouped under the
table kind intentionally: in a multi-pass workflow (first pass emits CREATE
TABLE + constraints, second pass adds only FKs), you don't want OWNER TO
re-emitted in the second pass. When you say except_kinds => ARRAY['table']
you are explicitly asking for sub-object DDL only, and ownership is a
table-level property. The owner flag says "include ownership if you're
emitting table-level DDL"; it doesn't override the kind filter.

Reply via email to