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 1vBT9d-00GyAr-F9 for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 07:21:04 +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 1vBT9b-00DumD-Af for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Oct 2025 07:21:02 +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.94.2) (envelope-from ) id 1vBT9a-00Dum3-V8 for pgsql-hackers@lists.postgresql.org; Wed, 22 Oct 2025 07:21:02 +0000 Received: from mail-vs1-xe31.google.com ([2607:f8b0:4864:20::e31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBT9Y-0037Im-08 for pgsql-hackers@postgresql.org; Wed, 22 Oct 2025 07:21:01 +0000 Received: by mail-vs1-xe31.google.com with SMTP id ada2fe7eead31-59dff155dc6so3319961137.3 for ; Wed, 22 Oct 2025 00:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761117659; x=1761722459; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QhEf6aaXTjH0dBBgMs3kTccdJEuofQosXESdmVOTNCM=; b=jvIm47sxObl6fB+5tRfZ8xFESybuOwAdpt0hW0Y1Y9KqU/OjMQKIgX7UWqK9PdqafE dAO0B6aMmIim9aMJeXklGWT/gahEi+Qu90T7rXSyU/7fbpjJwYsTTZpbHVGbSFx/wk4M oDLSfEi3w0AR9xcdTL32uWA2Adxu8eySgt0l3vE6WtZVJpN+tV90+G4cSUEyye9UPe2R HZ55rJHRUDbFmkJEkOB090GO1Uurv1vIel4X5W17pIDAi6nL8alpnyWuzIk0mLgSYIRP 2dnvsRY+567kQSVGrsdDoy2wPOL9/YG7us/7qC7IugCXp89pH5u8N/KyVcSLgyCiJ2ku Yl0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761117659; x=1761722459; h=content-transfer-encoding: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=QhEf6aaXTjH0dBBgMs3kTccdJEuofQosXESdmVOTNCM=; b=nxzC1gAnzSrzrSLaXNoD8lWpe9J5PGkR8IqhgHSl99f8sNLuPzxBfJ8cqTWR8894rr Fk/e2aH8MBK5pwr3EDw6p1/eOpFq8hdiTbZrmlrAfyOZRrHKjd+d4w17yzTKgZ69AEXP pooppf/R7XQhp3fpxLdYPaSdFrROwEF0LOl0bnW30OKVyTPd5bPj5y1mG2p+cEr3nEQM JztBNj96R5STCWWxNkCLZIYkCvOuoujFdjj5ATdWzqbTfBm7FKQXQR/nxqlva9qUn0KD 4QAZgH57q3rEV1rAuSSpSSPS6LIw50iC2w9j/u/ZFMIVIVmjmhSAOtiMvNvwrekUREyO BTZw== X-Forwarded-Encrypted: i=1; AJvYcCWwmiYc/jWTayxgQAzWdFa44ws4ZZKQ+ApBHsNRn2zF+KM9OVIItI8x6DxX3T2rSD65vdEsZhBXQTyou3MT@postgresql.org X-Gm-Message-State: AOJu0YwlUODKl2uBSMbsZ8XEVktR3IkipguOwu4tGW++CLexKS7Vk8Zd 2LblK9PZgJx96qUOtJzVDbF2Alkn4x8fy6IA8q60EEZwQ+29a8HCaGff1+tWxhwMxTzmR5hHAL9 V3IW4ybHKoIxzvuuetsLhioY6g50GlhI= X-Gm-Gg: ASbGncvo6M1wL5FU8ih5Vy4suSij97XZ1O7xGwDTjiABwNXxOEXSKE+E2nNe1f65ov1 Fy75CyQ74jEcv59jOFSdl9NudmnjCJhw3kMyru68f/A2wW0lnIyq+ZqGV2V60R2v8RkszVFs28V Z5stKXJvcGpYlQdn5OZiOtlnhe6gE1K7BqSqpTBGTKrXG1NvRBIaCSPuJeEc8M+yG6CKeYgJrH+ ukUkOmF7VSToQdVIyAUolJC8ClhJzdGfJ+0HtCiyG0UbxHwj5+ZSJYv3A3dP+dKKiSCf8rZO/wC WqXG6i78EYZJPRKbwtLtJcncY7iwEpObu6+ljPf5pwkbzV/aqlRXyX1pFYoz4xvuNc0pf5k2LSB uJ7QeZOwwqPlFUUaUa3osJJQNnCNnAc/jPYwpAlQ0YkxamOP2IGLJH0nKqfpW0mGW9FFxtCMwNf dn/g== X-Google-Smtp-Source: AGHT+IGkI6r0TmOZPD4/c3yueW1TseI5c5Hk+oYMmp3Va7pjF1iO5za7T/xQElj90Y+CrucpeFB/UzaJSBur6cj71RQ= X-Received: by 2002:a05:6102:dcb:b0:5d6:31f8:bf0 with SMTP id ada2fe7eead31-5d7dd6a44aemr6723433137.20.1761117658791; Wed, 22 Oct 2025 00:20:58 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: jian he Date: Wed, 22 Oct 2025 15:20:21 +0800 X-Gm-Features: AS18NWCC5UgDi7skfPi7o5l8hn-QowK1uCx6K7PwdiO6Slwg8W0FvHAkHB7YPfY Message-ID: Subject: Re: [PATCH] Add pg_get_policy_ddl() function to reconstruct CREATE POLICY statement To: Akshay Joshi Cc: Philip Alger , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 16, 2025 at 8:51=E2=80=AFPM Akshay Joshi wrote: > > Please find attached the v3 patch, which resolves all compilation errors = and warnings. > drop table if exists t, ts, ts1; create table t(a int); CREATE POLICY p0 ON t FOR ALL TO PUBLIC USING (a % 2 =3D 1); SELECT pg_get_policy_ddl('t', 'p0', false); pg_get_policy_ddl --------------------------------------------------------------------- CREATE POLICY p0 ON t AS PERMISSIVE FOR ALL USING (((a % 2) =3D 1)); (1 row) "TO PUBLIC" part is missing, maybe it's ok. SELECT pg_get_policy_ddl(-1, 'p0', false); ERROR: could not open relation with OID 4294967295 as I mentioned in a nearby thread [1], this should be NULL instead of ERROR= . [1] https://postgr.es/m/CACJufxGbE4uJWu1YuqdmOx+7PMBpHvX_fbRMmHu=3Dr4SrsuW9= tg@mail.gmail.com IMHO, get_formatted_string is not needed, most of the time, if pretty is tr= ue, we append "\t" and "\n", for that we can simply do ``` appendStringInfo(&buf, "CREATE POLICY %s ON %s ", quote_identifier(NameStr(*policyName)), generate_qualified_relation_name(policy_form->polrelid)); if (pretty) appendStringInfoString(buf, "\t\n"); ``` in pg_get_triggerdef_worker, I found the below code pattern: /* * In non-pretty mode, always schema-qualify the target table name for * 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",