Re: CREATE TABLE LIKE INCLUDING POLICIES

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: CREATE TABLE LIKE INCLUDING POLICIES
Date: 2026-01-21 15:22:54
Message-ID: CAN4CZFML9_MV1ryKKtNzP+GJA46JBk7OWtG7V=XWYEkqEQdaZA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello!

Generally looks good to me, the tests work, the new feature seem to
work, I only noticed a few minor things.

parse_utilcmd.c:2204
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot convert whole-row table reference"),
+ errdetail("Security policy \"%s\" contains a whole-row reference to
table \"%s\".",
+ NameStr(policy_form->polname),
+ RelationGetRelationName(parent_rel)));

The outer parentheses are missing after "ERROR, "

Same issue at line 2232.

parse_utilcmd:1634
+ policy_form = (Form_pg_policy) GETSTRUCT(tuple);
+
+ polrels = PolicyGetRelations(policy_form->oid);

Shouldn't the function free polrels after the foreach below?

policy.c:1357
+
+ relation_close(depRel, AccessShareLock);
+

Shouldn't that be table_close?

create_table.sgml:760
+ All row-level security policies are copied to the new table.
+ Note that by default row-level security is not enabled to
the new table,
+ using <command>ALTER TABLE ... ENABLE ROW LEVEL SECURITY</command>
+ in order for created policies to be applied to the new table.

Maybe "use ALTER TABLE ... ENABLE ROW LEVEL SECURITY to copy existing
policies to the new table"?

I am also wondering if this shouldn't be at least an option for CREATE
TABLE AS. This seems like something that's very easy to overlook and
accidentally forget.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Geier 2026-01-21 15:36:18 Use correct collation in pg_trgm
Previous Message Andrey Silitskiy 2026-01-21 15:11:47 Re: Exit walsender before confirming remote flush in logical replication