snow stage execute

Execute immediate all files from the stage path. Files can be filtered with glob like pattern, e.g. @stage/*.sql, @stage/dev/*. Only files with .sql extension will be executed.

Syntax

snow stage execute
  <stage_path>
  --on-error <on_error>
  --variable <variables>
  --connection <connection>
  --host <host>
  --port <port>
  --account <account>
  --user <user>
  --password <password>
  --authenticator <authenticator>
  --private-key-file <private_key_file>
  --token-file-path <token_file_path>
  --database <database>
  --schema <schema>
  --role <role>
  --warehouse <warehouse>
  --temporary-connection
  --mfa-passcode <mfa_passcode>
  --enable-diag
  --diag-log-path <diag_log_path>
  --diag-allowlist-path <diag_allowlist_path>
  --format <format>
  --verbose
  --debug
  --silent
Copy

Arguments

stage_path

Stage path with files to be execute. For example @stage/dev/*.

Options

--on-error [break|continue]

What to do when an error occurs. Defaults to break. Default: break.

--variable, -D TEXT

Variables for the execution context. For example: -D "<key>=<value>". For SQL files variables are use to expand the template and any unknown variable will cause an error. For Python files variables are used to update os.environ dictionary. Provided keys are capitalized to adhere to best practices.In case of SQL files string values must be quoted in '' (consider embedding quoting in the file).

--connection, -c, --environment TEXT

Name of the connection, as defined in your config.toml. Default: default.

--host TEXT

Host address for the connection. Overrides the value specified for the connection.

--port INTEGER

Port for the connection. Overrides the value specified for the connection.

--account, --accountname TEXT

Name assigned to your Snowflake account. Overrides the value specified for the connection.

--user, --username TEXT

Username to connect to Snowflake. Overrides the value specified for the connection.

--password TEXT

Snowflake password. Overrides the value specified for the connection.

--authenticator TEXT

Snowflake authenticator. Overrides the value specified for the connection.

--private-key-file, --private-key-path TEXT

Snowflake private key file path. Overrides the value specified for the connection.

--token-file-path TEXT

Path to file with an OAuth token that should be used when connecting to Snowflake.

--database, --dbname TEXT

Database to use. Overrides the value specified for the connection.

--schema, --schemaname TEXT

Database schema to use. Overrides the value specified for the connection.

--role, --rolename TEXT

Role to use. Overrides the value specified for the connection.

--warehouse TEXT

Warehouse to use. Overrides the value specified for the connection.

--temporary-connection, -x

Uses connection defined with command line parameters, instead of one defined in config. Default: False.

--mfa-passcode TEXT

Token to use for multi-factor authentication (MFA).

--enable-diag

Run python connector diagnostic test. Default: False.

--diag-log-path TEXT

Diagnostic report path. Default: <temporary_directory>.

--diag-allowlist-path TEXT

Diagnostic report path to optional allowlist.

--format [TABLE|JSON]

Specifies the output format. Default: TABLE.

--verbose, -v

Displays log entries for log levels info and higher. Default: False.

--debug

Displays log entries for log levels debug and higher; debug logs contains additional information. Default: False.

--silent

Turns off intermediate output to console. Default: False.

--help

Displays the help text for this command.

Usage notes

  • The command searches for files with a .sql extension in the specified STAGE_PATH and executes EXECUTE IMMEDIATE on each of them. STAGE_PATH can be:

    • Only a stage name, such as @scripts, which executes all .sql files from the stage.

    • Glob-like pattern, such as @scripts/dir/*, which executes .sql files from the dir directory.

    • Direct file path, such as @scripts/script.sql, which executes only the script.sql file from the scripts.

The --silent options hides intermediate messages with file execution results.

When using Jinja templates for the SQL files, you can pass template variables using -D (or --variable) option, such as -D "<key>=<value>". You must enclose string values in single quotes ('').

Examples

  • Specify only a stage name to execute all .sql files in the stage:

    snow stage execute "@scripts"
    
    Copy
    SUCCESS - scripts/script1.sql
    SUCCESS - scripts/script2.sql
    SUCCESS - scripts/dir/script.sql
    +------------------------------------------+
    | File                   | Status  | Error |
    |------------------------+---------+-------|
    | scripts/script1.sql    | SUCCESS | None  |
    | scripts/script2.sql    | SUCCESS | None  |
    | scripts/dir/script.sql | SUCCESS | None  |
    +------------------------------------------+
    
  • Specify a glob-like pattern to execute all .sql files in the dir directory:

    snow stage execute "@scripts/dir/*"
    
    Copy
    SUCCESS - scripts/dir/script.sql
    +------------------------------------------+
    | File                   | Status  | Error |
    |------------------------+---------+-------|
    | scripts/dir/script.sql | SUCCESS | None  |
    +------------------------------------------+
    
  • Specify a glob-like pattern to execute only .sql files in the dir directory that begin with “script”, followed by one character:

    snow stage execute "@scripts/script?.sql"
    
    Copy
    SUCCESS - scripts/script1.sql
    SUCCESS - scripts/script2.sql
    +---------------------------------------+
    | File                | Status  | Error |
    |---------------------+---------+-------|
    | scripts/script1.sql | SUCCESS | None  |
    | scripts/script2.sql | SUCCESS | None  |
    +---------------------------------------+
    
  • Specify a direct file path with the --silent option:

    snow stage execute "@scripts/script1.sql" --silent
    
    Copy
    +---------------------------------------+
    | File                | Status  | Error |
    |---------------------+---------+-------|
    | scripts/script1.sql | SUCCESS | None  |
    +---------------------------------------+