Hi,
Inspired by this message [1], introduce CREATE TABLE LIKE INCLUDING PRIVILEGES.
With this, the source table ACL stored in pg_class.relacl and
pg_attribute.attacl will now be copied to the target table.
This functionality only works if the current user is also the owner of
the source table.
Demo:
CREATE ROLE alice;
CREATE ROLE bob;
SET ROLE alice;
CREATE TABLE src (a int, b int);
GRANT INSERT ON src TO bob WITH GRANT OPTION;
CREATE TABLE dst (LIKE src INCLUDING PRIVILEGES);
SELECT relacl FROM pg_class WHERE relname = 'dst';
relacl
-------------------------------------
{alice=arwdDxtm/alice,bob=a*/alice}
[1]: https://www.postgresql.org/message-id/546590.1771005826%40sss.pgh.pa.us
--
jian
https://www.enterprisedb.com/