Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w8IDM-000OGX-2h for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 13:36:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8IDL-006752-1r for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 13:36:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w8IDL-00674u-0O for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 13:36:03 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w8IDJ-00000000Bxy-0WYb for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 13:36:02 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7d7c77fd31cso840797a34.3 for ; Thu, 02 Apr 2026 06:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775136960; cv=none; d=google.com; s=arc-20240605; b=VMmIVy95JE+EUZiDOLV3YMSSw6eilskOJ7q5xQ+otDUrrCn93sqzme38GBeomsvsBR oQ364bjVm8cyrNVMTa2/lbGRk+IsMmOywGk/CGxIhTNWV2UupQV+JaBdsFT+Tbth72GQ 6Tibrk2qy8me6r+vFeJJO59JCam4llX16fg7X2AYnDNMJuPIJihLiNVgReO3hqU6b+0a pEnACvKYG10en0GYkDTCMyvVyFccp5zGEdgE+dPapf6fJ+2S9NQqKVhpX2EmFShksVhw JVMHJCdBnQzXAKfAN75WdT8GVX3hBRfXACMOg+9ixOqV9maVuWv8M5HvmrzoNWMW9FCH GCkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:dkim-signature; bh=kwX91hQwLHRsIb8CFTu8ERHyoscelzxC5Wsbaz6TWMU=; fh=QuvkvZabXi3lr8oU2eRKozDU6U6wOumB+bVOi/lw53o=; b=DDLC3HWtrhRVhRKD4VvAxcPOBqCy1t/YRohbl5T3JxNfavoDWiIq4GOwXUmKqLlMQz xQVWMZ66Pj7sGfJeFssqP7uEg/YSROSHb1PVAiVFLz1622myZCGbqV2VozTdSa3qrQV4 JOZPQxXugBcboOmxvkaBDKQOheOTnUbJG0tTYZlPuuphYW7LmCoTFZAYL1hYxvqUkuUr cesr8tApeMRQSP9T4dnj/JDBEmDIcnnVMBSbPOvdqplkf+vr+ITi4sKyz+G2/VCgpT29 wAFNaA/Yl7drTpP/4/9/64eucyl0KznpnXW+vZeE4BPiD3yn9G/wx8QMSeNYK1EbcdAj /XaA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775136960; x=1775741760; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kwX91hQwLHRsIb8CFTu8ERHyoscelzxC5Wsbaz6TWMU=; b=oB7s9BFvZbxgemrL6vgupiHX7X85d5+YdAL5zhgjLDaskobEHcN5Orl2aMoQ7Uqs+6 2wC1ai5qJbwzQyneA8ytqugVp5ujkATRURwVAsYAN8NPcwC3h9BCauYGH0ROyyFuOZ1l XENXdQE7mFP0JLjmb8/UidY2wb/Pmm14SK1kTKLFzV5YaOc6nPqWIN7DwYMLyrbFFR6Q AxUIgae71axA9dAWcd77jy6zI+A/GEGKBQFHAcQwCJVi850Vzhj4FtWRhnDYAGOe5Ozl uZ11srMadcYXxeT+V8aC/YsWU9p7XWr4YPUPZAYiJd4J6QIu6uv1JX0ktzCBTU0Ri0w6 xGJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775136960; x=1775741760; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kwX91hQwLHRsIb8CFTu8ERHyoscelzxC5Wsbaz6TWMU=; b=OkfkH0YVQbR6kjK/gFPI889S5IS6wRw1CwOCjLn9ZHa12cJLfObHoTMFAbII8CIen8 +Y/4yf04qTEwjwTG141p+fzejU5iZLYYwxtE7w8k+J2vlS8Z0mDQD0y+KYKpN6sZ08HE TVqMfsdgd3I+hjtywI0Kk/NdQqOng/W1fyLurNYROTR21nbt2z2ybO9dIcRkWIj+m+sB gysJO7jMSOH2TejzFMCE3t1nHW9d0nZE8QQGtPGPhU9eRg6CZ4MpGKTSSKWZ7ehR5F61 m82CejXVfhbFUYj9x28d9R8FycVtYOjKOX1O1PwlhXCIgevJtSVQ17d2XZxoA6Wiy3lz EuFg== X-Forwarded-Encrypted: i=1; AJvYcCW84+komB1C+ngXCMESlBjObp/u38z20J1pEOsHYykoJMaxrxFhRUDsDEuPipJGqOzmc973e15IG45nw1UB@lists.postgresql.org X-Gm-Message-State: AOJu0YyFq4cUmirRQ65Jca5VRY9sja4fuSKbprfb2CWKdb0xOevrXzGA CLnD5yHBnSmK4Cct/vRjWzObsbp+HYqbObK/W/JcpgHSZgjaVoW0pETz3ghS6mme0Nh08E2JAqk iQuTIq8gLXoEgRy0wiwGB3953cmiBDWk= X-Gm-Gg: ATEYQzyIPeSsLgGFWdF4Nlw01tXysnwQos38ev3GZ8sIsRB7qZk+ibnRiChtjnfw6J7 7+OQCHMO2aXzc3TAz3bPs26EgSjWmZHMXhcpJH+VVshXzNQwTEtVtDrJZ+GIkXToD+JsEn+HLkv FAUBOdTOs63s6VtW9qU05IEqi0vkmqjgy0GDjEuTQe63sA88QA8PR1fMPB+mkap1nJ2b34z44YV aZVotfhYWh7t1vb8Ly95eJZCNZYJkxYMLtJXEXAQU8SfXE3MDuKMnDOMkWe+MEvW8F2lh5mVEyh 3NfzKO0DBuTu3wOGLDA5Kowza2QTdnzcORk5oFk6 X-Received: by 2002:a05:6820:2006:b0:67b:b7fb:28b1 with SMTP id 006d021491bc7-67fabc0681bmr4128992eaf.24.1775136960557; Thu, 02 Apr 2026 06:36:00 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6802:4a16:b0:625:99af:f56c with HTTP; Thu, 2 Apr 2026 06:35:59 -0700 (PDT) In-Reply-To: References: <202603201311.yhtqmvektawm@alvherre.pgsql> <8ec9b67d-939e-4b22-8d56-a5129f92d32d@app.fastmail.com> <555cdee4-c024-4872-9d96-82ef4216239c@dunslane.net> From: "David G. Johnston" Date: Thu, 2 Apr 2026 06:35:59 -0700 X-Gm-Features: AQROBzDiMb4dUchB5ujaqTZ1_Vq0GxulI8zQ4_pc7t_n-_n3TEDUb4WF71mOwII Message-ID: Subject: Re: pg_get__*_ddl consolidation To: Japin Li Cc: Andrew Dunstan , Zsolt Parragi , Euler Taveira , =?UTF-8?Q?=C3=81lvaro_Herrera?= , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000f636b5064e7a4755" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f636b5064e7a4755 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thursday, April 2, 2026, Japin Li wrote: > > v3-0004 > =3D=3D=3D=3D=3D=3D=3D=3D > > 1. > + append_ddl_option(&buf, pretty, 4, "WITH TEMPLATE =3D template0")= ; > > I'm curious why WITH TEMPLATE =3D template0 is hardcoded. For example: > > [local]:1374846 postgres=3D# create database db01 IS_TEMPLATE true; > CREATE DATABASE > [local]:1374846 postgres=3D# create database db02 template db01; > CREATE DATABASE > [local]:1374846 postgres=3D# select pg_get_database_ddl('db02'); > pg_get_database_ddl > ------------------------------------------------------------ > ----------------------------------------------------- > CREATE DATABASE db02 WITH TEMPLATE =3D template0 ENCODING =3D 'UTF8' > LOCALE_PROVIDER =3D libc LOCALE =3D 'en_US.UTF-8'; > ALTER DATABASE db02 OWNER TO japin; > (2 rows) > > Is this working as expected? > > It seems there's no way to reconstruct the WITH TEMPLATE clause, right? > A comment here would help. There is no way or use in constructing the original template clause, though I agree it=E2=80=99s worth a comment. At the end of the day the catalog da= ta that was found in the db01 database already exists in the db02 database when executing these DLL reconstruction functions against the existing db02 database. Taking nothing from the template is the correct behavior - hence template0. David J. --000000000000f636b5064e7a4755 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thursday, April 2, 2026, Japin Li <japinli@hotmail.com> wrote:
<= br>v3-0004
=3D=3D=3D=3D=3D=3D=3D=3D

1.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0append_ddl_option(&buf, pretty, 4, "WI= TH TEMPLATE =3D template0");

I'm curious why WITH TEMPLATE =3D template0 is hardcoded. For example:<= br>
=C2=A0 [local]:1374846 postgres=3D# create database db01 IS_TEMPLATE true;<= br> =C2=A0 CREATE DATABASE
=C2=A0 [local]:1374846 postgres=3D# create database db02 template db01;
=C2=A0 CREATE DATABASE
=C2=A0 [local]:1374846 postgres=3D# select pg_get_database_ddl('db02= 9;);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0pg_get_database_ddl
=C2=A0 -----------------------------------------------------------------------------------------------------------------
=C2=A0 =C2=A0CREATE DATABASE db02 WITH TEMPLATE =3D template0 ENCODING =3D = 'UTF8' LOCALE_PROVIDER =3D libc LOCALE =3D 'en_US.UTF-8'; =C2=A0 =C2=A0ALTER DATABASE db02 OWNER TO japin;
=C2=A0 (2 rows)

Is this working as expected?

It seems there's no way to reconstruct the WITH TEMPLATE clause, right?=
A comment here would help.

There is no way = or use in constructing the original template clause, though I agree it=E2= =80=99s worth a comment.=C2=A0 At the end of the day the catalog data that = was found in the db01 database already exists in the db02 database when exe= cuting these DLL reconstruction functions against the existing db02 databas= e.=C2=A0 Taking nothing from the template is the correct behavior - hence t= emplate0.

David J.

--000000000000f636b5064e7a4755--