database_roles
Creates, updates, deletes, gets or lists a database_roles
resource.
Overview
Name | database_roles |
Type | Resource |
Id | snowflake.database_role.database_roles |
Fields
The following fields are returned by SELECT
queries:
- list_database_roles
A Snowflake database role
Name | Datatype | Description |
---|---|---|
name | string | Name of the database role (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
comment | string | User comment associated to an object in the dictionary |
created_on | string (date-time) | Date and time when the database role was created |
granted_database_roles | integer (int64) | How many database roles this database role has been granted |
granted_to_database_roles | integer (int64) | How many database roles this database role has been granted to |
granted_to_roles | integer (int64) | How many roles this database role has been granted to |
owner | string | Role that owns the database role (pattern: ^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$) |
owner_role_type | string | The 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:
Name | Accessible by | Required Params | Optional Params | Description |
---|---|---|---|---|
list_database_roles | select | database_name , endpoint | showLimit , fromName | List database roles |
create_database_role | insert | database_name , endpoint | createMode | Create a database role |
delete_database_role | delete | database_name , name , endpoint | ifExists | Delete a database role |
clone_database_role | exec | database_name , name , endpoint | createMode , targetDatabase | Create 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.
Name | Datatype | Description |
---|---|---|
database_name | string | Identifier (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. |
endpoint | string | Organization and Account Name (default: orgid-acctid) |
name | string | Identifier (i.e. name) for the resource. |
createMode | string | Query 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. |
fromName | string | Query 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. |
ifExists | boolean | Query 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. |
showLimit | integer | Query parameter to limit the maximum number of rows returned by a command. |
targetDatabase | string | Database of the target resource. Defaults to the source's database |
SELECT
examples
- list_database_roles
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_database_role
- Manifest
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 }}'
;
# Description fields are for documentation purposes
- name: database_roles
props:
- name: database_name
value: string
description: Required parameter for the database_roles resource.
- name: endpoint
value: string
description: Required parameter for the database_roles resource.
- name: name
value: string
description: >
Name of the database role
- name: comment
value: string
description: >
User comment associated to an object in the dictionary
- name: createMode
value: string
description: Query 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.
DELETE
examples
- delete_database_role
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
- clone_database_role
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 }}"
}';