On Sat, Feb 14, 2026 at 2:03 AM Tom Lane <[email protected]> wrote:
>
> jian he <[email protected]> writes:
> > +CREATE TABLE coll_t1(LIKE coll_t INCLUDING POLICIES);
>
> I want to take a step back and debate whether such a feature is
> a good idea at all.
>

IMHO, It's generally a good thing to make the target table produced by
CREATE TABLE LIKE be very close to the source table.

> What's bothering me in particular is that CREATE TABLE LIKE does
> not (and cannot be told to) copy the source's ownership or ACL
> permissions.  Does it make sense to copy RLS policies while
> not copying those tightly-associated properties?  I'm inclined to
> think not.
>
ok. I will first think about how doable it's to implement:
CREATE TABLE LIKE INCLUDING ACL.

> I'm especially distressed that this would presumably cause
> INCLUDING ALL to copy policies too.  I think the odds of that
> usually being the right thing would be small.
>

https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-DISABLE-ENABLE-ROW-LEVEL-SECURITY
>>>>>QUOTE
Note that policies can exist for a table even if row-level security is
disabled. In this case, the policies will not be applied and the
policies will be ignored.
>>>>>QUOTE

https://www.postgresql.org/docs/current/sql-createpolicy.html
>>>>>QUOTE
Note that row-level security must be enabled on the table (using ALTER
TABLE ... ENABLE ROW LEVEL SECURITY) in order for created policies to
be applied.
>>>>>QUOTE

CREATE TABLE coll_t1(LIKE coll_t INCLUDING ALL);
source table's policy will copied, and will not applied.

It copies source table objects, and you must manually execute another
command (ALTER TABLE ... ENABLE ROW LEVEL SECURITY) for it to take
effect.
When you are executing ALTER TABLE ... ENABLE ROW LEVEL SECURITY, you
obviously understand what you are doing.

So this is safe?



--
jian
https://www.enterprisedb.com/


Reply via email to