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 1vyPkL-0005wW-17 for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2026 07:37:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vyPkJ-003NrO-2e for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2026 07:37:16 +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 1vyPkJ-003NrG-0y for pgsql-hackers@lists.postgresql.org; Fri, 06 Mar 2026 07:37:16 +0000 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vyPkH-00000000jkm-28PQ for pgsql-hackers@postgresql.org; Fri, 06 Mar 2026 07:37:14 +0000 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-8cb5c9ba82bso1412949185a.2 for ; Thu, 05 Mar 2026 23:37:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772782633; cv=none; d=google.com; s=arc-20240605; b=fdMI+w1Au7ATRbb+1p86qB0sVpqkZsM6CyzTH6jjY2aaX4ynGz7OAcnQ0OIZKZD/e7 chDWzwB4b6DF97ZnV0dAG2VUbXcN7+kGyNBLkAlkkT3SBnEVBackjqRwHTcW3M8oEHT/ LECqzgWvvI0osBH2rJ44MoKmss7uBkYWluePlxRHvNQy2qNeZz+01kZNRrMKf7eXZYfE m/Hi/HurGTtMIcZlBnV7soiIqqcgh+Oxk4KEbyXtLOZsY7GAFCWWXpELm4pifZ6TikEx 3jPhbxrY/55HRciDekgSKWQUsHZJhRVLrsdQATaVdeOpQGnElnzQ5cpqeshmmgLCvSNh q5JQ== 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:in-reply-to:references :mime-version:dkim-signature; bh=+VCrxpahoPTExZ5tAW2jcSFozJ9UXiXkxcBhLf61QBI=; fh=NCWYIch53XyYQThVHiQd5XhZDP71WJTZv2S1UvUv4y0=; b=YYEY5hik257eMuihwaKWuYs0i2MMj2vBftE1u+aMm/VFAUeNaF3IQj0DbXY/+p/xxo fT9h9aAInb7gFjIqwPD29B65/IbASiAHKxdgYiKlQPOCt/Zqv8t5ZM1L/HQqS5oR7I/1 1mRtdYooMgZ/BsfAaQ6P1TmcMQ/n6SSrjOzDd/OTwvhtCPmhLZOixa0Usvn7cde4Xi5A QxVvg6RcLo4sHAmknryRA8P4ftNySJNVmZ+SAzp5xSSLQT/PMVu6hh/AvYKxx4+rAv/e ltVKH3X2aQmNIziw/kHkrlqc/l4LcnXuz6G6WncU7sRdhnpQRsI8XnZEYQxsc1WiKFLs YQBA==; darn=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=20230601; t=1772782633; x=1773387433; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+VCrxpahoPTExZ5tAW2jcSFozJ9UXiXkxcBhLf61QBI=; b=ZZV2wNDUk05fA8xWkyvr07yJzTADDIBL8ZA/G1f+9mSyLKDKIbjhE0qZ2+RVI1cqe6 0WTb+nvUSLwlzgDT0l0l3/3xGOQ05DXIN7ZE2p5igyTz2+yBGdPZiI0mtxCs3Pj5NPEI PCUkOjol311JsKL/kvVd/z05tFasxZmGPq70vEUOzNWv94R9j1A8h2ifA5ubGnyE1C6C a6H0Ou+FAorelf4+RoQ6yTCNG/2lP4sF1FSu5Fpy+dOYq6OGrxlvozNqqu1n5x8AMMpq uLTIT0EFLHyoN8Pf3xyX7BqgEZhF8O26PX1/FtUjVNCpNopQYINHhlqMTa05+v55rfiF gvUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772782633; x=1773387433; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+VCrxpahoPTExZ5tAW2jcSFozJ9UXiXkxcBhLf61QBI=; b=bjiPk5ABxjZKMW2AYyUkzV3rPoh315ou/I8NpeDpEOWrE72ehGLK3nrpvpuW8MKzbL Qc1l7Qf9DmyEc+bAFsu86sFLhtU6+lRb89elaTyTy4TXAMGHFVa7mrEdb+GuLrUoy3of VPrB9Bzfuu67PPEpO0ei8dR9hceIWnHtpy8rgqzSqbkLpbM2+3yI/LyOtATqILrCUrM+ zayqJ2TO2x7/PsEwDEeqXUfYFdtPRvZ2o1OiFoHo194lQL/S0rWZyEZYW8BqhCQyqx2q cuOdyWyFFvk7RBi0YoMSherYFIQH8Yc0i9zHTHqfCJktW4i/5TaW1rgistr1hscRe6T5 n/CA== X-Forwarded-Encrypted: i=1; AJvYcCXWgug0/IMbeXvTVb1ywk7DrKkBoDYZ5Bs96Gp2x3moAozg5+CZZtQa7Yr4RoDQfXx+zByrP7FK0r5HoG00@postgresql.org X-Gm-Message-State: AOJu0YxEYfRXuT6gBTBvSktU6MxOR3E+VG6A1eWDFEkRZBu9CcsB/EOL z1c6G5VVLAAPjMR8ebidihv066F9x24CC9RcaKPfY78L+cXaiDXw40/ukbPtGjVBXkwKn0YeJ0G vEymKI7LEmJQpHCrGHUaG05SFug6ONXo= X-Gm-Gg: ATEYQzxGuMJS/CvLipbgRghIoaB97U0TrtA90lbtUknl/MUa+EB8LId7u53RSaTGgON CNusdzvW4ujJ5UTTIGtRaH4vs3VG9wki9UZvgffLiU6vxHQkudI+KMWWUk+0NJJ1YRbYVpke4n+ 4Zomy3bMBCEl/xpiAWztHJtuLCFb9AL8vZHfor3xb2rJxx79SGSJwzAjImKra7P2nMr17fu5Sol wwEL8SkNzz/wiW100RLsI7to3eK4sw4bxsqD5qEWwu0cl5nh8tQtLcF+ZnjwHVA1JxciFf58LTl wvi9nMFEhXqUruNxEHAC05TOIvbI7tDJJJiDTL0bdqWJ29249B/weV016ratZHeiyhKj2XO3men MtTbn X-Received: by 2002:a05:620a:4114:b0:8c9:f4eb:ac71 with SMTP id af79cd13be357-8cd6d3fb5e8mr145113385a.10.1772782632753; Thu, 05 Mar 2026 23:37:12 -0800 (PST) MIME-Version: 1.0 References: <202603040943.2jvgphmddgcs@alvherre.pgsql> In-Reply-To: From: Rafia Sabih Date: Thu, 5 Mar 2026 23:37:01 -0800 X-Gm-Features: AaiRm50DoCt4FyZ7rowcgvoZMk2reYQCxFKn6TgWWz-qz0-07ef3rCuqQ1GvERs Message-ID: Subject: Re: [PATCH] Add pg_get_database_ddl() function to reconstruct CREATE DATABASE statement To: Akshay Joshi Cc: Japin Li , =?UTF-8?Q?=C3=81lvaro_Herrera?= , Euler Taveira , Amul Sul , Andrew Dunstan , Chao Li , Quan Zongliang , pgsql-hackers Content-Type: multipart/alternative; boundary="00000000000016dda5064c561f09" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000016dda5064c561f09 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 5 Mar 2026 at 08:16, Akshay Joshi wrote: > > > On Thu, Mar 5, 2026 at 8:15=E2=80=AFPM Rafia Sabih > wrote: > >> I like the idea for this patch and find this useful. >> >> I have few comments for the patch, looking at the test cases added in th= e >> patch, it is not clear to me what is the default value for each of the >> options. For example, in >> > > Following the postgresql documentation, I created ddl_defaults.h to > handle default options. This will be used across all database objects in > future pg_get__ddl patches. > > >> +-- With No Tablespace >> +SELECT ddl_filter(pg_get_database_ddl('regression_utf8', 'defaults', >> true, 'tablespace', false)); >> + >> ddl_filter >> >> >> +-----------------------------------------------------------------------= ---------------------------------------------------------------------------= -------- >> + CREATE DATABASE regression_utf8 WITH OWNER =3D regress_datdba_after >> ENCODING =3D 'UTF8' ALLOW_CONNECTIONS =3D true CONNECTION LIMIT =3D 123 >> IS_TEMPLATE =3D false; >> +(1 row) >> + >> owner option is omitted but the output contains the owner information. S= o >> does it mean that the default value for each option is true? >> But that doesn't seem so, because omitting pretty option, doesn't give >> output in pretty, rather pretty is used only when provided. >> I find this rather confusing, it is worth documenting what is the defaul= t >> value for each of these options. >> > > In my view, every database has an owner; it's a required attribute, > not an optional one with a "default" value. The OWNER clause is correctly > controlled only by the PG_DDL_NO_OWNER flag. Users must explicitly provid= e (*'owner', > false/'no'/'off')* to opt out of including ownership info in the > DDL. When comparing the Owner and Pretty options: by default, the Owner i= s > included in the DDL reconstruction, whereas the Pretty option is set to > false by default. > > Right, I think this needs to be added in the documentation as part of thi= s patch. Basically, here + 'pretty', true (or 'pretty', 'yes'): + Adds newlines and indentation for better readability. + it needs to have a line more saying, by default this option is off. Similarly for other options, like for the owner it is by default true, etc. > In my initial patches, I used flags like --no-owner and > --no-tablespace because they are very intuitive for users. However, > reviewers noted that this style is unique to pg_dump and not used > elsewhere. Consequently, I switched to the existing name-value pair forma= t > using VARIADIC arguments. > >> >> Similarly, what is the expected behaviour when defaults option is not >> provided, >> +-- With No Owner >> +SELECT ddl_filter(pg_get_database_ddl('regression_utf8', 'owner', >> false)); >> + ddl_filter >> +-------------------------------------------------------------- >> + CREATE DATABASE regression_utf8 WITH CONNECTION LIMIT =3D 123; >> +(1 row) >> + >> +-- With No Tablespace >> +SELECT ddl_filter(pg_get_database_ddl('regression_utf8', 'defaults', >> true, 'tablespace', false)); >> + >> ddl_filter >> >> >> +-----------------------------------------------------------------------= ---------------------------------------------------------------------------= -------- >> + CREATE DATABASE regression_utf8 WITH OWNER =3D regress_datdba_after >> ENCODING =3D 'UTF8' ALLOW_CONNECTIONS =3D true CONNECTION LIMIT =3D 123 >> IS_TEMPLATE =3D false; >> +(1 row) >> Why is connection_limit present in both of these cases...? >> >> Another thing, what is the significance of having defaults option, >> because I think that knowing non-default values could be more useful, or >> atleast there should be a way to know the non-default options for the >> database. >> > > The defaults option is false by default; if a user does not specify > it, the reconstructed DDL only includes non-default parameters. In my > opinion, we should retain this flag for users who wish to see all availab= le > parameters for easier manual editing later. While simple database objects > have fewer parameters, this flag is essential for complex TABLE or FUNCTI= ON > syntax where the parameter list is extensive. > This information should also be included in the documentation. > > >> Also, the option strategy is missing in the output, is it deliberate? If >> yes, why? >> > >> On Thu, 5 Mar 2026 at 01:50, Akshay Joshi >> wrote: >> >>> I=E2=80=99ve addressed all of your comments. >>> >>> Attached is the *v11 patch*, now ready for further review. >>> >>> On Wed, Mar 4, 2026 at 7:31=E2=80=AFPM Japin Li w= rote: >>> >>>> On Wed, 04 Mar 2026 at 18:29, Akshay Joshi < >>>> akshay.joshi@enterprisedb.com> wrote: >>>> > Thanks for the review, Japin. I=E2=80=99ve addressed all of your com= ments. I >>>> also added a check to throw an error if an option >>>> > appears more than once. >>>> > >>>> > Attached is the v10 patch, now ready for further review. >>>> > >>>> >>>> Thanks for updating the patch. Here are some comments on v10. >>>> >>>> 1. >>>> + * db_oid - OID/Name of the database for which to generate the DDL. >>>> >>>> Should the comment be updated? The code only accepts an OID for >>>> `db_oid`, >>>> database names are not supported. >>>> >>>> 2. >>>> + /* Set the OWNER in the DDL if owner is not omitted */ >>>> + if (OidIsValid(dbform->datdba) && !(ddl_flags & >>>> PG_DDL_NO_OWNER)) >>>> + { >>>> + get_formatted_string(&buf, pretty_flags, 8, "OWNER =3D >>>> %s", >>>> + >>>> quote_identifier(dbowner)); >>>> + } >>>> >>>> `dbowner` is only needed inside this `if` =E2=80=94 how about declarin= g it >>>> there to >>>> reduce its scope? >>>> >>>> 3. >>>> + /* If is_with_defaults is true, then we skip default >>>> encoding check */ >>>> + if (is_with_defaults || >>>> + >>>> (pg_strcasecmp(pg_encoding_to_char(dbform->encoding), >>>> + >>>> DDL_DEFAULTS.DATABASE.ENCODING) !=3D 0)) >>>> + { >>>> + get_formatted_string(&buf, pretty_flags, 8, >>>> "ENCODING =3D %s", >>>> + >>>> quote_literal_cstr( >>>> + >>>> pg_encoding_to_char(dbform->encoding)= )); >>>> + } >>>> >>>> How about cache the result of `pg_encoding_to_char()` in a local >>>> variable to >>>> avoid calling it twice? >>>> >>>> -- >>>> Regards, >>>> Japin Li >>>> ChengDu WenWu Information Technology Co., Ltd. >>>> >>> >> >> -- >> Regards, >> Rafia Sabih >> CYBERTEC PostgreSQL International GmbH >> > --=20 Regards, Rafia Sabih CYBERTEC PostgreSQL International GmbH --00000000000016dda5064c561f09 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Thu, 5 Mar 2= 026 at 08:16, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:


On = Thu, Mar 5, 2026 at 8:15=E2=80=AFPM Rafia Sabih <rafia.pghackers@gmail.com> w= rote:
I like the idea for this patch and find this useful.

I have few comments for the patch, looking at the test cas= es added in the patch, it is not clear to me what is the default=C2=A0value= for each of the options. For example, in

= =C2=A0 =C2=A0Following the postgresql documentation, I created=C2=A0d= dl_defaults.h=C2=A0to handle default options. This will be used acro= ss all database objects in future=C2=A0pg_get_<object>_ddl=C2=A0patches.
=C2=A0
+-- With No Tablespace
+SELECT ddl_filter(p= g_get_database_ddl('regression_utf8', 'defaults', true, = 9;tablespace', false));
+ =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=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ddl_filter = =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=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
+---------------------------------------= ---------------------------------------------------------------------------= ----------------------------------------
+ CREATE DATABASE regression_ut= f8 WITH OWNER =3D regress_datdba_after ENCODING =3D 'UTF8' ALLOW_CO= NNECTIONS =3D true CONNECTION LIMIT =3D 123 IS_TEMPLATE =3D false;
+(1 r= ow)
+
owner option is omitted but the=C2=A0output contains the= owner information. So does it mean that the default value for each option = is true?
But that doesn't seem so,=C2=A0because omitting pret= ty option, doesn't give output in pretty, rather pretty is used only wh= en provided.
I find this rather confusing, it is worth documentin= g what is the default value for each of these options.

=C2=A0 =C2=A0 In my view, every database has an owner; it'= s a required attribute, not an optional one with a "default" valu= e.=C2=A0The OWNER clause is correctly controlled only by the PG_DDL_NO_OWNE= R flag. Users must explicitly provide ('owner', false/'no= 9;/'off')=C2=A0to opt out of including ownership info in the DD= L.=C2=A0When comparing the Owner and Pretty options: by default, the Owner = is included in the DDL reconstruction, whereas the Pretty option is set to = false by default.

Right, I think= this needs to be added in the documentation as part of this patch. Basical= ly, here
<para>
+ =C2=A0 =C2=A0 =C2=A0<literal>'pre= tty', true</literal> (or <literal>'pretty', 'ye= s'</literal>):
+ =C2=A0 =C2=A0 =C2=A0Adds newlines and indenta= tion for better readability.
+ =C2=A0 =C2=A0 =C2=A0</para>
it needs to have a line more saying, by default this option is off.= Similarly for other options, like for the owner it is by default true, etc= .
<= div class=3D"gmail_quote">
=C2=A0 =C2=A0=C2=A0In my initial patches, I = used flags like --no-owner and --no-tablespace because they are very intuit= ive for users. However, reviewers noted that this style is unique to pg_dum= p and not used elsewhere. Consequently, I switched to the existing name-val= ue pair format using VARIADIC arguments.

Similarly, what i= s the expected behaviour when defaults option is not provided,
+-= - With No Owner
+SELECT ddl_filter(pg_get_database_ddl('regression_u= tf8', 'owner', false));
+ =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=A0ddl_filter =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
+------------------------------------------------------------= --
+ CREATE DATABASE regression_utf8 WITH CONNECTION LIMIT =3D 123;
+= (1 row)
+
+-- With No Tablespace
+SELECT ddl_filter(pg_get_databas= e_ddl('regression_utf8', 'defaults', true, 'tablespace&= #39;, false));
+ =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=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ddl_filter =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=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0
+-----------------------------------------------------= ---------------------------------------------------------------------------= --------------------------
+ CREATE DATABASE regression_utf8 WITH OWNER = =3D regress_datdba_after ENCODING =3D 'UTF8' ALLOW_CONNECTIONS =3D = true CONNECTION LIMIT =3D 123 IS_TEMPLATE =3D false;
+(1 row)
= Why is connection_limit present in both of these cases...?

Another thing, what is the significance of having defaults option,= because I think that knowing non-default values could be more useful, or a= tleast there should be a way to know=C2=A0 the non-default options for the = database.

=C2=A0 =C2=A0 The defaults optio= n is false by default; if a user does not specify it, the reconstructed DDL= only includes non-default parameters. In my opinion, we should retain this= flag for users who wish to see all available parameters for easier manual = editing later. While simple database objects have fewer parameters, this fl= ag is essential for complex TABLE or FUNCTION syntax where the parameter li= st is extensive.
This information sh= ould also be included in the documentation.=C2=A0
<= div>=C2=A0 =C2=A0 =C2=A0
Also, the option strategy is missing in the outp= ut, is it deliberate? If yes, why?=C2=A0

On Thu, 5 Mar 2026 at 01:50, Akshay Joshi= <aks= hay.joshi@enterprisedb.com> wrote:

I=E2=80=99ve addressed all of= your comments.

Attached is the=C2=A0v11 patch, now ready for = further review.


On Wed, Mar 4, 2026 at 7:31=E2=80=AFPM Japin Li <japinli@hotmail.com> wrote:
On = Wed, 04 Mar 2026 at 18:29, Akshay Joshi <akshay.joshi@enterprisedb.com> w= rote:
> Thanks for the review, Japin. I=E2=80=99ve addressed all of your comme= nts. I also added a check to throw an error if an option
> appears more than once.
>
> Attached is the v10 patch, now ready for further review.
>

Thanks for updating the patch.=C2=A0 Here are some comments on v10.

1.
+ * db_oid - OID/Name of the database for which to generate the DDL.

Should the comment be updated? The code only accepts an OID for `db_oid`, database names are not supported.

2.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* Set the OWNER in the DDL if owner is not omi= tted */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (OidIsValid(dbform->datdba) && !(= ddl_flags & PG_DDL_NO_OWNER))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0get_formatted_strin= g(&buf, pretty_flags, 8, "OWNER =3D %s",
+=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=A0 =C2=A0 =C2=A0 =C2=A0 quote_identifier(dbowner))= ;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0}

`dbowner` is only needed inside this `if` =E2=80=94 how about declaring it = there to
reduce its scope?

3.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* If is_with_defau= lts is true, then we skip default encoding check */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (is_with_default= s ||
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(pg_strcasecmp(pg_encoding_to_char(dbform->encoding),
+=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=A0 DDL_DEFAULTS.DATABASE.ENCODING) !=3D 0))
+=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=A0get_formatted_string(&buf, pretty_flags, 8, "ENCODING = =3D %s",
+=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=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 quote_literal_cstr(
+=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=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=A0 =C2=A0 =C2=A0 =C2=A0pg_enc= oding_to_char(dbform->encoding)));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}

How about cache the result of `pg_encoding_to_char()` in a local variable t= o
avoid calling it twice?

--
Regards,
Japin Li
ChengDu WenWu Information Technology Co., Ltd.


--
Regards,
Rafia Sabih
CYBERTEC PostgreSQL = International GmbH


--
Regards,
Rafia Sabih
CYBERTEC PostgreSQL = International GmbH
--00000000000016dda5064c561f09--