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

NameDatatypeDescription
namestringName of the database role
commentstringUser comment associated to an object in the dictionary
created_onstringDate and time when the database role was created
granted_database_rolesintegerHow many database roles this database role has been granted
granted_to_database_rolesintegerHow many database roles this database role has been granted to
granted_to_rolesintegerHow many roles this database role has been granted to
ownerstringRole that owns the database role
owner_role_typestringThe type of role that owns the database role

Methods

NameAccessible byRequired ParamsOptional ParamsDescription
list_database_rolesSELECTdatabase_name, endpointshowLimit, fromNameList database roles
create_database_roleINSERTdatabase_name, data__name, endpointcreateModeCreate a database role
delete_database_roleDELETEdatabase_name, name, endpointifExistsDelete a database role
clone_database_roleEXECdatabase_name, name, data__name, endpointcreateMode, targetDatabaseCreate a new database role by cloning from the specified resource

Optional Parameter Details
NameDescriptionTypeDefault
createModeQuery 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.stringerrorIfExists
fromNameQuery 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.string-
ifExistsQuery 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.booleanfalse
showLimitQuery parameter to limit the maximum number of rows returned by a command.integer-
targetDatabaseDatabase of the target resource. Defaults to the source's databasestring-

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 }}'
AND endpoint = '{{ endpoint }}';

INSERT example

Use the following StackQL query and manifest file to create a new database_roles resource.

/*+ create */
INSERT INTO snowflake.database_role.database_roles (
data__name,
data__comment,
database_name,
endpoint
)
SELECT
'{{ name }}',
'{{ comment }}',
'{{ database_name }}',
'{{ endpoint }}'
;

DELETE example

Deletes the specified database_roles resource.

/*+ delete */
DELETE FROM snowflake.database_role.database_roles
WHERE database_name = '{{ database_name }}'
AND name = '{{ name }}'
AND endpoint = '{{ endpoint }}';