Skip to main content

database_roles

Creates, updates, deletes, gets or lists a database_roles resource.

Overview

Namedatabase_roles
TypeResource
Idsnowflake.database_role.database_roles

Fields

The following fields are returned by SELECT queries:

A Snowflake database role

NameDatatypeDescription
namestringName of the database role (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
commentstringUser comment associated to an object in the dictionary
created_onstring (date-time)Date and time when the database role was created
granted_database_rolesinteger (int64)How many database roles this database role has been granted
granted_to_database_rolesinteger (int64)How many database roles this database role has been granted to
granted_to_rolesinteger (int64)How many roles this database role has been granted to
ownerstringRole that owns the database role (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)
owner_role_typestringThe type of role that owns the database role (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
list_database_rolesselectdatabase_name, endpointshowLimit, fromNameList database roles
create_database_roleinsertdatabase_name, endpointcreateModeCreate a database role
delete_database_roledeletedatabase_name, name, endpointifExistsDelete a database role
clone_database_roleexecdatabase_name, name, endpointcreateMode, targetDatabaseCreate a new database role by cloning from the specified resource

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
database_namestringIdentifier (i.e. name) for the database to which the resource belongs. You can use the /api/v2/databases GET request to get a list of available databases.
endpointstringOrganization and Account Name (default: orgid-acctid)
namestringIdentifier (i.e. name) for the resource.
createModestringQuery parameter allowing support for different modes of resource creation. Possible values include: - errorIfExists: Throws an error if you try to create a resource that already exists. - orReplace: Automatically replaces the existing resource with the current one. - ifNotExists: Creates a new resource when an alter is requested for a non-existent resource.
fromNamestringQuery parameter to enable fetching rows only following the first row whose object name matches the specified string. Case-sensitive and does not have to be the full name.
ifExistsbooleanQuery parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn't exist.
showLimitintegerQuery parameter to limit the maximum number of rows returned by a command.
targetDatabasestringDatabase of the target resource. Defaults to the source's database

SELECT examples

List database roles

SELECT
name,
comment,
created_on,
granted_database_roles,
granted_to_database_roles,
granted_to_roles,
owner,
owner_role_type
FROM snowflake.database_role.database_roles
WHERE database_name = '{{ database_name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
AND showLimit = '{{ showLimit }}'
AND fromName = '{{ fromName }}';

INSERT examples

Create a database role

INSERT INTO snowflake.database_role.database_roles (
data__name,
data__comment,
database_name,
endpoint,
createMode
)
SELECT
'{{ name }}' --required,
'{{ comment }}',
'{{ database_name }}',
'{{ endpoint }}',
'{{ createMode }}'
;

DELETE examples

Delete a database role

DELETE FROM snowflake.database_role.database_roles
WHERE database_name = '{{ database_name }}' --required
AND name = '{{ name }}' --required
AND endpoint = '{{ endpoint }}' --required
AND ifExists = '{{ ifExists }}';

Lifecycle Methods

Create a new database role by cloning from the specified resource

EXEC snowflake.database_role.database_roles.clone_database_role 
@database_name='{{ database_name }}' --required,
@name='{{ name }}' --required,
@endpoint='{{ endpoint }}' --required,
@createMode='{{ createMode }}',
@targetDatabase='{{ targetDatabase }}'
@@json=
'{
"name": "{{ name }}"
}';