CREATE VARIABLE

statementsupportedUDFs, procedures, tasks, alerts, scripting

docs.snowflake.com ↗

Object: VARIABLE

Creates a new schema variable, a named, typed, persistent scalar value scoped to a schema.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] VARIABLE [ IF NOT EXISTS ] <name> <data_type>
  [ DEFAULT <default_value> ]
  [ COMMENT = '<string_literal>' ]

Parameters

NameRequiredDescription
namerequiredSpecifies the identifier for the variable. The identifier must be unique within the schema. The identifier can be optionally qualified with the schema name (schema.variable_name) or with both the database and schema names (database.schema.variable_name). For more details, see Identifier requirements.
data_typerequiredSpecifies the data type of the variable. All scalar Snowflake data types are supported. The value stored in the variable must be assignment-compatible with this type. For the list of supported types, see Summary of data types.
DEFAULT default_valueoptionalSpecifies the initial value for the variable. The expression is evaluated at creation time and must produce a value compatible with data_type. If omitted, the variable’s initial value is NULL. The default can be changed after creation with ALTER VARIABLE … SET DEFAULT.
COMMENT = 'string_literal'optionalSpecifies a comment for the variable. Default: No value

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE VARIABLE | Schema | OWNERSHIP | Variable | Required to execute a CREATE OR REPLACE VARIABLE statement for an existing variable. OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). Note that in a managed access schema, only the schema owner (i.e. the role with the OWNERSHIP privilege on the schema) or a role with the MANAGE GRANTS privilege can grant or revoke privileges on objects in the schema, including future grants. Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

See also

Referenced by