Skip to main content

databases

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

Overview

Namedatabases
TypeResource
Idsnowflake.database.databases

Fields

NameDatatypeDescription
namestringA Snowflake object identifier. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.
budgetstringBudget that defines a monthly spending limit on the compute costs for a Snowflake account or a custom group of Snowflake objects.
commentstringOptional comment in which to store information related to the database.
created_onstringDate and time the database was created.
data_retention_time_in_daysintegerSpecifies the number of days for which Time Travel actions (CLONE and UNDROP) can be performed on the database, as well as specifying the default Time Travel retention time for all schemas created in the database.
default_ddl_collationstringDefault collation specification for all schemas and tables added to the database. You an override the default at the schema and individual table levels.
dropped_onstringDate and time the database was dropped.
is_currentbooleanCurrent database for the session.
is_defaultbooleanWhether the database is the default database for a user.
kindstringDatabase type, permanent (default) or transient.
log_levelstringSeverity level of messages that should be ingested and made available in the active event table. Currently, Snowflake supports only TRACE, DEBUG, INFO, WARN, ERROR, FATAL and OFF.
max_data_extension_time_in_daysintegerMaximum number of days for which Snowflake can extend the data retention period for tables in the database to prevent streams on the tables from becoming stale.
optionsstring
originstring
ownerstringName of the role that owns the database.
owner_role_typestringType of role that owns the object, either ROLE or DATABASE_ROLE
retention_timeintegerNumber of days that historical data is retained for Time Travel.
serverless_task_max_statement_sizestringSpecifies the maximum allowed warehouse size for the serverless task. Minimum XSMALL, Maximum XXLARGE.
serverless_task_min_statement_sizestringSpecifies the minimum allowed warehouse size for the serverless task. Minimum XSMALL, Maximum XXLARGE.
suspend_task_after_num_failuresintegerMaximum number of consecutive failed task runs before the current task is suspended automatically.
trace_levelstringHow trace events are ingested into the event table. Currently, Snowflake supports only ALWAYS, ON_EVENT, and OFF.
user_task_managed_initial_warehouse_sizestringSize of the compute resources to provision for the first run of the serverless task, before a task history is available for Snowflake to determine an ideal size.
user_task_timeout_msintegerTime limit, in milliseconds, for a single run of the task before it times out.

Methods

NameAccessible byRequired ParamsDescription
fetch_databaseSELECTname, endpointFetches a database.
list_databasesSELECTendpointLists the accessible databases.
create_databaseINSERTdata__name, endpointCreates a database, with modifiers as query parameters. You must provide the full database definition when creating a database.
delete_databaseDELETEname, endpointDeletes the specified database. If you enable the ifExists parameter, the operation succeeds even if the database does not exist. Otherwise, a 404 failure is returned if the database does not exist. if the drop is unsuccessful.
create_or_alter_databaseREPLACEname, data__name, endpointCreates a new, or alters an existing, database. You must provide the full database definition even when altering an existing database.
clone_databaseEXECname, endpointClones an existing database, with modifiers as query parameters. You must provide the full database definition when cloning an existing database.
create_database_from_shareEXECendpointCreates a database from a given share.
create_database_from_share_deprecatedEXECname, endpointCreates a database from a given share.
disable_database_failoverEXECname, data__accounts, endpointDisables failover for this primary database, meaning no replica of this database (i.e. secondary database) can be promoted to serve as the primary database.
disable_database_replicationEXECname, data__accounts, endpointDisables replication for this primary database, meaning no replica of this database (i.e. secondary database) in another account can be refreshed. Any secondary databases remain linked to the primary database, but requests to refresh a secondary database are denied.
enable_database_failoverEXECname, data__accounts, endpointSpecifies a comma-separated list of accounts in your organization where a replica of this primary database can be promoted to serve as the primary database.
enable_database_replicationEXECname, data__accounts, endpointPromotes a local database to serve as a primary database for replication. A primary database can be replicated in one or more accounts, allowing users in those accounts to query objects in each secondary (i.e. replica) database.
primary_database_failoverEXECname, endpointPromotes the specified secondary (replica) database to serve as the primary database. When promoted, the database becomes writeable. At the same time, the previous primary database becomes a read-only secondary database.
refresh_database_replicationEXECname, endpointRefreshes a secondary database from a snapshot of its primary database. A snapshot includes changes to the objects and data. If you call this endpoint while another refresh for the same replica database is running, it fails and returns an error. Snowflake ensures only one refresh is executed at any given time.
undrop_databaseEXECname, endpointUndrops database.

SELECT examples

Lists the accessible databases.

SELECT
name,
budget,
comment,
created_on,
data_retention_time_in_days,
default_ddl_collation,
dropped_on,
is_current,
is_default,
kind,
log_level,
max_data_extension_time_in_days,
options,
origin,
owner,
owner_role_type,
retention_time,
serverless_task_max_statement_size,
serverless_task_min_statement_size,
suspend_task_after_num_failures,
trace_level,
user_task_managed_initial_warehouse_size,
user_task_timeout_ms
FROM snowflake.database.databases
WHERE endpoint = '{{ endpoint }}';

INSERT example

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

/*+ create */
INSERT INTO snowflake.database.databases (
data__name,
data__kind,
data__comment,
data__data_retention_time_in_days,
data__default_ddl_collation,
data__log_level,
data__max_data_extension_time_in_days,
data__suspend_task_after_num_failures,
data__trace_level,
data__user_task_managed_initial_warehouse_size,
data__serverless_task_min_statement_size,
data__serverless_task_max_statement_size,
data__user_task_timeout_ms,
endpoint
)
SELECT
'{{ name }}',
'{{ kind }}',
'{{ comment }}',
'{{ data_retention_time_in_days }}',
'{{ default_ddl_collation }}',
'{{ log_level }}',
'{{ max_data_extension_time_in_days }}',
'{{ suspend_task_after_num_failures }}',
'{{ trace_level }}',
'{{ user_task_managed_initial_warehouse_size }}',
'{{ serverless_task_min_statement_size }}',
'{{ serverless_task_max_statement_size }}',
'{{ user_task_timeout_ms }}',
'{{ endpoint }}'
;

REPLACE example

Replaces all fields in the specified databases resource.

/*+ update */
REPLACE snowflake.database.databases
SET
name = '{{ name }}',
kind = '{{ kind }}',
comment = '{{ comment }}',
data_retention_time_in_days = '{{ data_retention_time_in_days }}',
default_ddl_collation = '{{ default_ddl_collation }}',
log_level = '{{ log_level }}',
max_data_extension_time_in_days = '{{ max_data_extension_time_in_days }}',
suspend_task_after_num_failures = '{{ suspend_task_after_num_failures }}',
trace_level = '{{ trace_level }}',
user_task_managed_initial_warehouse_size = '{{ user_task_managed_initial_warehouse_size }}',
serverless_task_min_statement_size = '{{ serverless_task_min_statement_size }}',
serverless_task_max_statement_size = '{{ serverless_task_max_statement_size }}',
user_task_timeout_ms = '{{ user_task_timeout_ms }}'
WHERE
name = '{{ name }}'
AND data__name = '{{ data__name }}'
AND endpoint = '{{ endpoint }}';

DELETE example

Deletes the specified databases resource.

/*+ delete */
DELETE FROM snowflake.database.databases
WHERE name = '{{ name }}'
AND endpoint = '{{ endpoint }}';