Skip to main content

database_roles

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

Overview

Namedatabase_roles
TypeResource
Idsnowflake.roles.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
listselectdatabase_name, endpointshowLimit, fromNameList database roles
createinsertdatabase_name, endpoint, namecreateModeCreate a database role
deletedeletedatabase_name, name, endpointifExistsDelete a database role
cloneexecdatabase_name, name, endpoint, namecreateMode, 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 identifier (orgname-accountname) (default: orgname-accountname)
namestringIdentifier (i.e. name) for the resource.
createModestringParameter 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.
fromNamestringParameter 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.
ifExistsbooleanParameter 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.
showLimitintegerParameter 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.roles.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.roles.database_roles (
name,
comment,
database_name,
endpoint,
createMode
)
SELECT
'{{ name }}' /* required */,
'{{ comment }}',
'{{ database_name }}',
'{{ endpoint }}',
'{{ createMode }}'
RETURNING
status
;

DELETE examples

Delete a database role

DELETE FROM snowflake.roles.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.roles.database_roles.clone
@database_name='{{ database_name }}' --required,
@name='{{ name }}' --required,
@endpoint='{{ endpoint }}' --required,
@createMode='{{ createMode }}',
@targetDatabase='{{ targetDatabase }}'
@@json=
'{
"name": "{{ name }}"
}'
;