CTobi
CTobi

Reputation: 11

Question about CREATE TABLE ... CLONE {COPY GRANTS} behaviour

I am new to Snowflake and I am confused about the CREATE TABLE ... CLONE COPY GRANTS explanations of the documentation and what I see when trying:

The CREATE TABLE … CLONE syntax includes the COPY GRANTS keywords, which affect a new table clone as follows: https://docs.snowflake.com/en/sql-reference/sql/create-clone.html [1]

Object Cloning: https://docs.snowflake.com/en/sql-reference/sql/grant-privilege.html [2]

The link 1. of the documentation indicates that not using COPY GRANTS inherits the source table privileges but not the future ones and the link 2. (bold line) indicates that not using COPY GRANTS inherits the future privileges I am quite confused of the interpretation. Moreover I tried to clone a table with and without the COPY GRANTS option : with COPY GRANTS the initial privileges of the source table appears in the clone, without COPY GRANT there are no privileges (except the OWNER). But in the 2 cases future grants on the source table never inherits the clone table. Could someone help me in the understanding ? 😊 Thanks a lot, Regards, Cyril

Upvotes: 1

Views: 8101

Answers (1)

Gokhan Atil
Gokhan Atil

Reputation: 10079

It seems you found a bug on the documents. When you use COPY GRANTS, the cloned table will inherit any explicit access privileges granted on the original table.

create role test_role;

create table test_table (v varchar);

grant update on future tables in schema public to test_role;

grant select on test_table to role test_role;

show grants on test_table;

+-----------+------------+--------------+
| privilege | granted_on | grantee_name |
+-----------+------------+--------------+
| OWNERSHIP | TABLE      | ACCOUNTADMIN |
| SELECT    | TABLE      | TEST_ROLE    |
+-----------+------------+--------------+

create table clone_table_nocp clone test_table;

create table clone_table_yescp clone test_table copy grants;

show grants on clone_table_nocp; -- has future grants of schema

+-----------+--------------+
| privilege | grantee_name |
+-----------+--------------+
| OWNERSHIP | ACCOUNTADMIN |
| UPDATE    | TEST_ROLE    |
+-----------+--------------+

show grants on clone_table_withcp; -- inherited access privileges, but does not have future grants 

+-----------+--------------+
| privilege | grantee_name |
+-----------+--------------+
| OWNERSHIP | ACCOUNTADMIN |
| SELECT    | TEST_ROLE    |
+-----------+--------------+

I will contact with the documentation team to fix it.

Upvotes: 3

Related Questions