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 1w9P3J-001PFi-2t for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 15:06:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9P3I-003RZv-11 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 15:06:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w9P3H-003RZh-2l for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 15:06:16 +0000 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9P3F-00000000k9U-2Q7w for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 15:06:16 +0000 Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-89cd8596724so39861186d6.0 for ; Sun, 05 Apr 2026 08:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20251104.gappssmtp.com; s=20251104; t=1775401572; x=1776006372; darn=lists.postgresql.org; h=in-reply-to:autocrypt:content-language:references:cc:to:from :subject:user-agent:mime-version:date:message-id:from:to:cc:subject :date:message-id:reply-to; bh=pVLchRgUV90dr7cCBuH3AaYJz4l+Brw+YdEs7MxCV0Y=; b=E+RLdKo/0qoYSkzGi7P9L/8PO+dR0jCgvj062zUi/uIH77HTXJwVbF1RYXc7re7ZAd 97Z429/0HTh1diGCJ6KgzgVjrr+3GgZ96QvdUJ5GacuLzIwhkMymslM82phQbiOIr2LW FojIqIqLGQjI+pDWORluzadslKY+fzK1dIIq9Y99zbEfLAaJPZ2cJac7klkinA2pP8qe AUeJfxGBsSa0FYO2zNJYBYfGgU+fgylFzAYdcYm6R+cQAuaa351tnIIZPv+Sihzjy+y9 j01UaQTmHUZN+0N6BTFso+rUCWpPWdb9bkeusNKl2FQPhg/RKto5VmLw3+ig7orbmL/s Nykw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775401572; x=1776006372; h=in-reply-to:autocrypt:content-language:references:cc:to:from :subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pVLchRgUV90dr7cCBuH3AaYJz4l+Brw+YdEs7MxCV0Y=; b=btzmdX1ycd7B++uF/l6mLYV/whjwDDwfPWvPKZVBG2/eqMkY3UIgyCk/SJ/5Z9KK8E XvY3yimf1ABGe7k7fBUuwUng2ogZSJvecFguCW65Pw2lf8oEaNLqaXwHx8EeSTCSmtVO P0CHmum6gx2Y74GcUa71Zm+Xct2Ue0abTCtg0HfZxbsg8AyoBs5qP3jMyeFpKwZMjv+Q QE4lNJTZg0bJzy4rGYCa3C5xqcDo8CRi1z2XMg3gH/Z0Tm48lZSX3A54soBwfTvNVtxZ R9TVfuowROR86UR8ka0yXB0LN1zrEVMyjSPD00LT7X3n3NQbIvwQXzmAEIvxZ/7mOy4S yzJA== X-Forwarded-Encrypted: i=1; AJvYcCWwZs2l4yAGJNMBdxtUbEPgq5l77rMzM1nJ92xuckam7V4VUY/eIfM0H5gX3jA6Y443zzF26LDpiNht9ZN7@lists.postgresql.org X-Gm-Message-State: AOJu0Yx7TfgIfpXcynYSOGnGZm+jeCDufXDsWwVXn6g1aPq59MZ2q2Xr ubZA4f05rsHMKVHF0AThrEY1K7sSRbuDCC/jpfBCQe3qPwFQoYhAw1gNnoH+9uF2MhI= X-Gm-Gg: AeBDiet+zMyfT2dZdtH1lyYFe0Ewbk/ryvtn3TtgKv5YfPGB94Mmmjys4vle5gXK65z Ybh3LPRmXk237VouLpMAP4Fd1+MvOb3BaQmgW5pATaa4xzdPdTq9SY4sPI2fuK8aKDXurUh6Su4 Br0RfLsMpESQ9/yXRBSccZ5AwZAQN+lCLkvvknflVJ2BgoIJ1e0VQ2FyMyjTQnT17aMkmXytU1U zWjX9IlO2XxJUid1+ewt11KNolRBihM5FAKGJbK5yS0jYSZCcw/Hd6pOJ4sCXOGL2VAZnJe4A1I Tn0krR/xu/zixrf2kUJnjuIVZJxQOR02xcgjWIvEHeMLfxERBLksggqODek68S1l1myIipzNSS7 dGuGm7V94tBiupc/UKrtRQCTt4ZoY3SN6M39vMY6rjyYkc2I1XgFtWzIjF2kcI6KMxKvvsWAxxP 5/t/NOP7Jtnpz8wd2PLxVZxBmj4ZGwNg== X-Received: by 2002:a0c:e011:0:b0:8a1:fe5c:dc40 with SMTP id 6a1803df08f44-8a705387954mr128434166d6.51.1775401572103; Sun, 05 Apr 2026 08:06:12 -0700 (PDT) Received: from ?IPV6:2605:a601:a6b0:500::1cb? ([2605:a601:a6b0:500::1cb]) by smtp.googlemail.com with ESMTPSA id 6a1803df08f44-8a596ff619asm119803856d6.37.2026.04.05.08.06.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 Apr 2026 08:06:11 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------0d4iPodcNNqqJpUn4Nvrgu9m" Message-ID: Date: Sun, 5 Apr 2026 11:06:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pg_get__*_ddl consolidation From: Andrew Dunstan To: "David G. Johnston" , Japin Li Cc: Zsolt Parragi , Euler Taveira , =?UTF-8?Q?=C3=81lvaro_Herrera?= , PostgreSQL Hackers References: <202603201311.yhtqmvektawm@alvherre.pgsql> <8ec9b67d-939e-4b22-8d56-a5129f92d32d@app.fastmail.com> <555cdee4-c024-4872-9d96-82ef4216239c@dunslane.net> Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNJEFuZHJldyBEdW5zdGFuIDxhbmRyZXdAZHVuc2xhbmUubmV0PsLAlwQTAQgAQQIbAwIX gAIZAQULCQgHAwUVCgkICwUWAgMBAAIeBRYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNGd BQkdEO8nAAoJEJn6f8tZ/DuBq74H/jkTR4Zi3stbw+xC7v2u3QozssK7MYPL2AsVfh7OealS h182fiWXpfvmmAB7WUHbhk9GC2RAOnHI/2d2jgKaMLAHsGYOT0YopTVIwRY43fCw/mK67yxc wmDcX+zyKfLaivNbf5A7QPLNwda98bEAMSJ8Sn652Uc6cA8t3uKGsVzbRBQOoYzjgvBCfSrE 9ql3PDNg0l4BfAqabd2f70ZUm9VAMEPrgv/v2xI7M2XiL4g5BVmqLCOwxLM8RMCotCuoweUr VO43DeBCIDwLxotMJKvGWDjBzQYlU1NPUAtNcz/gN9ITUe1VUGjyvGj4u1lxBOcQQUw7l1+T 5moZ4iZxXzvOwE0ETspYWQEIANGc4zQULOxhbqO2dyD51YhqCNRmm9oKWaqf+wmW4tpDe/VV cxAnNizd4LWCHfzpb5cHAtGkOPePMfzWVf6nvdF7d3eglbtf59+zG7O7llV0xSSoFiieQBsr GvqDInXYX/4mRRXMtyhM353/tixC9RWLs1oofyYmCPPXXY7h9R7en3B8BoVrRFcdzlIY/NFN hFGW/9dkEiGjgna2Rk6e15kln4ZvFBWUg23p93w/pqXcxY6+k/8TEk+C4R+M6w7o2PLGOjdZ +kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaYL++LAEOqrlvm2Tvq QqZRtnEAEQEAAcLAfAQYAQgAJgIbDBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNI2BQkd EODdAAoJEJn6f8tZ/DuBfw0IAKTsfD40teP/pp+bsLLMSxPXUYrrprTj7WFB5v61p6dkpSr/ qXmMlyahdxQFaPmfVgVirB1Vk/kHiWNnnGjfUV9nB2Zg9LI0Xb9/ts3LsUiRWXzG3tkMY6XL vsVOxW4XFRND9l2q+WW93aZ1DZl+fqWfYgMvsusFRhmGFOKTRfKPta2Pkv+AhA24N4+PrR5p bU4k2MO8PAGiK8eaYKGFG1bHKuAvoDoF7WXJ3FHxuWqLnKEt4dfOLm5pAe3zq1Lt6q8azT9i QWGpSAK5vQUWQHBHpiDjdPeqKZ6HiAXIIKfSmb+jrvXBqoP+D6/K7rUjG2aXiRtTIAXms9sm VRu7cmw= In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------0d4iPodcNNqqJpUn4Nvrgu9m Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026-04-02 Th 12:27 PM, Andrew Dunstan wrote: > > > On 2026-04-02 Th 9:35 AM, David G. Johnston wrote: >> On Thursday, April 2, 2026, Japin Li wrote: >> >> >> v3-0004 >> ======== >> >> 1. >> +       append_ddl_option(&buf, pretty, 4, "WITH TEMPLATE = >> template0"); >> >> I'm curious why WITH TEMPLATE = template0 is hardcoded. For example: >> >>   [local]:1374846 postgres=# create database db01 IS_TEMPLATE true; >>   CREATE DATABASE >>   [local]:1374846 postgres=# create database db02 template db01; >>   CREATE DATABASE >>   [local]:1374846 postgres=# select pg_get_database_ddl('db02'); >>  pg_get_database_ddl >>   >> ----------------------------------------------------------------------------------------------------------------- >>    CREATE DATABASE db02 WITH TEMPLATE = template0 ENCODING = >> 'UTF8' LOCALE_PROVIDER = libc LOCALE = '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’s worth a comment.  At the end of the day the >> catalog data 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. >> >> > > > OK, here's a v4. > > > Pushed. I have moved the remaining get_*_ddl items to PG20-1 cheers andrew -- Andrew Dunstan EDB:https://www.enterprisedb.com --------------0d4iPodcNNqqJpUn4Nvrgu9m Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2026-04-02 Th 12:27 PM, Andrew Dunstan wrote:


On 2026-04-02 Th 9:35 AM, David G. Johnston wrote:
On Thursday, April 2, 2026, Japin Li <japinli@hotmail.com> wrote:

v3-0004
========

1.
+       append_ddl_option(&buf, pretty, 4, "WITH TEMPLATE = template0");

I'm curious why WITH TEMPLATE = template0 is hardcoded. For example:

  [local]:1374846 postgres=# create database db01 IS_TEMPLATE true;
  CREATE DATABASE
  [local]:1374846 postgres=# create database db02 template db01;
  CREATE DATABASE
  [local]:1374846 postgres=# select pg_get_database_ddl('db02');
                                                 pg_get_database_ddl
  -----------------------------------------------------------------------------------------------------------------
   CREATE DATABASE db02 WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = '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’s worth a comment.  At the end of the day the catalog data 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.




OK, here's a v4.




Pushed. I have moved the remaining get_*_ddl items to PG20-1


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com
--------------0d4iPodcNNqqJpUn4Nvrgu9m--