Re: CREATE TABLE LIKE INCLUDING POLICIES - Mailing list pgsql-hackers

From Zsolt Parragi
Subject Re: CREATE TABLE LIKE INCLUDING POLICIES
Date
Msg-id CAN4CZFOLJ5hvMbHiNPY3J9Emv19h1FV27LoeLZzWxFYMudh96w@mail.gmail.com
Whole thread Raw
In response to Re: CREATE TABLE LIKE INCLUDING POLICIES  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
> Actually, this extra parentheses is optional.

Thanks for the links, I thought this is a mandatory convention in PG.

> I noticed that the above RelationGetIndexList does not list_free
> parent_indexes as well.
> It should be ok not not call list_free polrels too, because as the memory
> allocation here is in portal context which should be reset by end of the current
> statement execution.

I mainly suggested that because here PolicyGetRelations is inside a
loop, so it allocates multiple lists, not just one per statement. It
might be still a low amount of memory, so maybe its good as is.

> how about ...

that sounds good to me.


> do you mean
> https://www.postgresql.org/docs/current/sql-createtableas.html
> to also copy RLS policies.

No, sorry, I meant to write CREATE TABLE LIKE there. What I meant is
that it might be better to enable the policies if they are enabled on
the parent table, or at least to have an option to do this, as this
seems easy to overlook (to assume that if it INCLUDING POLICIES, that
includes enabling them).

Especially because in most RLS examples/introduction, you first run
ALTER TABLE ENABLE ROW LEVEL SECURITY, and then add policies with
CREATE POLICY after that.

> if so, seems not doable, for example,
>
> create table x as select from tenk1, tenk2 limit 2;
>
> Should it copy all RLS policies from tenk1 and tenk2 to the new tables?

Now that I think about it, it still would be a nice option for simple
cases where people just want to duplicate a table

create table including policies table_copy as select * from table;

But that's definitely a different topic.



pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: DOCS - "\d mytable" also shows any publications that publish mytable
Next
From: Zsolt Parragi
Date:
Subject: Re: Use correct collation in pg_trgm