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.94.2) (envelope-from ) id 1vBdtu-0020x5-Rp for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 18:49:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vBdtt-000l1w-LH for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 18:49:32 +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.94.2) (envelope-from ) id 1vBdtt-000l1j-9m for pgsql-hackers@lists.postgresql.org; Wed, 22 Oct 2025 18:49:32 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBdtp-003f5Z-35 for pgsql-hackers@postgresql.org; Wed, 22 Oct 2025 18:49:31 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-42421b1514fso4592909f8f.2 for ; Wed, 22 Oct 2025 11:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761158968; x=1761763768; 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=QvdEb0i4+E0f85+A9ywa4b0prAqzuACmQ+iHqSZ12C4=; b=f9NHOXdouV+yI0+iWlhZLh16Isr/EqTSe5NRzzuDLJGtS2jXPsthST7JRCuKf5mnFQ 33an16+sc/FtELavJVkkA3ZnT6/Y4cwmeOmpQFlA7Yt/BDctlCC0e/zT6NjZqMofk86m Py6ZS9HcwUrcpldmerWziN1DdYhYlbkW5unQwPfZLVtzdiPWqJstKIPe5V62dTjF2sOf I3gBPDyBf79wt1BgNhKgcd4MBOpulHSlMuSJV+xXWIq99pgCtouE67UI1S7k6la+I9a3 hWd+eCQfwL4kzMtC9YJIjlyiOE03mF4LHTtBZc4YRUS1YUtRcPH++Aez21J+JS3wZ8yK 5yWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761158968; x=1761763768; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QvdEb0i4+E0f85+A9ywa4b0prAqzuACmQ+iHqSZ12C4=; b=A+PSxlcUjuOyozl1DuL0JzVo8VLNkUwy37gIiCBxvdI7+AZ4yfwFnpCPTUpcnFM+Zv fP+a68P4G6H+eysUdDbbeclXUbtpbAW7kqtu4Jj0QuWnKI0mKpKjkvCo5UwwUe6g7mrx tfQKMaXtH6GkCG8qesRMN8DAh5j6Z+dJqX/tml7qB5C9fAJx5nzTZ4kD45ZpGszsw9f4 6tJrgm/NrCU6vMuZF2ge6cvOMEIf9abynAcQjIgmOJ34BgEO6qjBgkJG11EzAzp05BRA H9fcu7PH4qmXmJCqlgoDimlCZpfqVpDnPeAJvDjahSXxSjLUFf1I7CD0nA/Eex1p2nA+ zL/g== X-Forwarded-Encrypted: i=1; AJvYcCX89VRvvf0wTfAiJRVINmy7VLi7liSbMfIRE2T02jwnCSsipRnvUT+NluSx4Vd203sHjATyyivN9EzcknzW@postgresql.org X-Gm-Message-State: AOJu0YwqELCuv1HhNIiQw7UMovcwawgk2RXrhMAvYNESessq/S7R3tsX 0L8R6d6ou8CY71YlXzgKHriulZ3FX4kGLpbCx1gwKsuYk9gjUmWmU8W+zHs1Y4gK6+AwUTW9D6l Sn1hhRn4ORX8oyAEA46gZov/siBakCQ== X-Gm-Gg: ASbGnct4tSt5Ny32kxUl5Op7pkULl701xHbClf+/UzKmcDUOAfaDeWb6+BloLolt12g OeyABrIZI0nI3y/HxaaHDQrjdd9mjPQO0K+N72MeZF2OHous3LNbn3N6QkHUqsbu/b3QNnPvKBL nNvGVoVUHtvJn8GSs52Z71g+TwQKXOEFCNVJcdcKns9bZNAyd/ZoHjEcyyzLi2TTOQQ9FD0QlOA 5oVmLPEWsmTVwnWc5mKdCnXGvIgZhk10LX+jMEqS4bZb46Cgbh69r0WYASJ X-Google-Smtp-Source: AGHT+IGQSyR096cQcjImLUrSEL/xGtBthPoZ6AHABWl3bu7/inM2EZ5XsdS6hLGxuOZS2+1Ea7fVX7kEW52N5CombBw= X-Received: by 2002:a05:6000:144d:b0:428:55c3:cea5 with SMTP id ffacd0b85a97d-42855c3d44cmr1942915f8f.11.1761158968373; Wed, 22 Oct 2025 11:49:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Philip Alger Date: Wed, 22 Oct 2025 13:49:17 -0500 X-Gm-Features: AS18NWBpvhWagGwjurIyW2qUIJ2GB0XEuMHWIPFTUstL7IQDNyPO_WDc-I6DtYI Message-ID: Subject: Re: [PATCH] Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statement To: Akshay Joshi Cc: jian he , pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000b3f8160641c3c67a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b3f8160641c3c67a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable >> The get_formatted_string function is needed. Instead of using multiple i= f > statements for the pretty flag, it=E2=80=99s better to have a generic fun= ction. > This will be useful if the pretty-format DDL implementation is accepted b= y > the community, as it can be reused by other pg_get__ddl() DDL > functions added in the future. > >> >> in pg_get_triggerdef_worker, I found the below code pattern: >> /* >> * In non-pretty mode, always schema-qualify the target table name f= or >> * safety. In pretty mode, schema-qualify only if not visible. >> */ >> appendStringInfo(&buf, " ON %s ", >> pretty ? >> generate_relation_name(trigrec->tgrelid, NIL) : >> generate_qualified_relation_name(trigrec->tgrelid))= ; >> >> maybe we can apply it too while construct query string: >> "CREATE POLICY %s ON %s", >> > > In my opinion, the table name should always be schema-qualified, which I > have addressed in the v4 patch. The implementation of the pretty flag > here differs from pg_get_triggerdef_worker, which is used only for the > target table name. In my patch, the pretty flag adds \t and \n to each > different clause (example AS, FOR, USING ...) > > I think that's where the confusion lies with adding `pretty` to the DDL functions. The `pretty` flag set to `true` on other functions is used to "not" show the schema name. But in the case of this function, it is used to format the statement. I wonder if the word `format` or `pretty_format` is a better name? `pretty` itself in the codebase isn't a very clear name regardless. --=20 Best, Phil Alger --000000000000b3f8160641c3c67a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable



The get_= formatted_string function is needed. Instead of using multiple if statements for the pretty flag, it=E2=80=99s better= to have a generic function. This will be useful if the pretty-format DDL i= mplementation is accepted by the community, as it can be reused by other pg= _get_<object>_ddl() DDL functions added in the future.=C2=A0

in pg_get_triggerdef_worker, I found the below code pattern:
=C2=A0 =C2=A0 /*
=C2=A0 =C2=A0 =C2=A0* In non-pretty mode, always schema-qualify the target = table name for
=C2=A0 =C2=A0 =C2=A0* safety.=C2=A0 In pretty mode, schema-qualify only if = not visible.
=C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 appendStringInfo(&buf, " ON %s ",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0pretty ?
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0generate_relation_name(trigrec->tgrelid, NIL) :
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0generate_qualified_relation_name(trigrec->tgrelid));

maybe we can apply it too while construct query string:
"CREATE POLICY %s ON %s",

In my opinion,= the table name should always be schema-qualified, which=C2=A0I have addres= sed in the v4 patch. The implementation of the pretty flag her= e differs from pg_get_triggerdef_worker, which is used only fo= r the target table name. In my patch, the pretty flag adds \t and \n to each different clause (example AS, FOR,= USING ...)
=C2=A0

I think that's whe= re the confusion=C2=A0lies with=C2=A0adding `pretty` to the DDL functions. = The `pretty` flag set to `true` on other=C2=A0functions is used to "no= t" show the schema name. But in the=C2=A0case of=C2=A0this function,= =C2=A0it is used to format the statement. I wonder if the word `format` or = `pretty_format` is a better name? `pretty` itself in the codebase isn't= a very clear name regardless.

--
Best,=C2=A0
Phil Alger
--000000000000b3f8160641c3c67a--