Bases: AccountObjectCollectionParent[RoleResource]
Represents the collection operations on the Snowflake Role resource.
With this collection, you can create, iterate through, and search for roles that you have access to in the current context.
Examples
Creating a role instance:
>>> role_collection = root.roles
>>> role_collection.create(Role(name="test-role", comment="samplecomment"))
Attributes
The Root object this collection belongs to.
Methods
Create a role in Snowflake.
role (Role) – The Role object, together with the Role’s properties:
name ; comment is optional
mode (CreateMode, optional) –
One of the following enum values.
CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError
if the role already exists in Snowflake. Equivalent to SQL create role <name> ....
CreateMode.or_replace: Replace if the role already exists in Snowflake. Equivalent to SQL
create or replace role <name> ....
CreateMode.if_not_exists: Do nothing if the role already exists in Snowflake.
Equivalent to SQL create role <name> if not exists...
Default is CreateMode.error_if_exists.
Examples
Creating a role, replacing any existing role with the same name:
>>> role = Role(name="test-role", comment="samplecomment")
>>> role_ref = root.roles.create(role, mode=CreateMode.or_replace)
An asynchronous version of create().
Refer to PollingOperation for more information on asynchronous execution and
the return type.
Iterate through Role objects from Snowflake, filtering on any optional ‘like’ pattern.
like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).
starts_with (str, optional) – String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.
show_limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is None, which behaves equivalently
to show_limit=10000. This value must be between 1 and 10000.
from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.
Examples
Showing all roles that you have access to see:
>>> roles = role_collection.iter()
Showing information of the exact role you want to see:
>>> roles = role_collection.iter(like="your-role-name")
Showing roles starting with ‘your-role-name-‘:
>>> roles = role_collection.iter(like="your-role-name-%")
>>> roles = role_collection.iter(starts_with="your-role-name")
Using a for loop to retrieve information from iterator:
>>> for role in roles:
... print(role.name, role.comment)
An asynchronous version of iter().
Refer to PollingOperation for more information on asynchronous execution and
the return type.
Update the collection with a new item.