Snowflake Scripting Developer Guide | Snowflake Documentation (original) (raw)
Topics in this section explain how to write a stored procedure in SQL by using Snowflake Scripting. Snowflake Scripting is an extension to Snowflake SQL that adds support for procedural logic. You can use Snowflake Scripting to write stored procedures and procedural code outside of a stored procedure. This guide explains how to use Snowflake Scripting.
Understanding blocks in Snowflake Scripting
Learn the basic structure of Snowflake Scripting code.
Declare and use variables.
Return values from stored procedures and an anonymous block.
Working with conditional logic
Control flow with IF and CASE statements.
Control flow with FOR, WHILE, REPEAT, and LOOP.
Iterate through query results with a cursor.
Iterate over the result set returned by a query.
Handle errors by handling and raising exceptions.
Determining the number of rows affected by DML commands
Use global variables to determine the effect of data manipulation language (DML) commands.
Getting the query ID of the last query
Use the global variable SQLID to get the query ID of the last query.
Examples for common use cases of Snowflake Scripting
Explore examples of Snowflake Scripting code for some common use cases.
Using Snowflake Scripting in Snowflake CLI, SnowSQL, the Classic Console, and Python Connector
Run the Snowflake Scripting examples in SnowSQL, the Classic Console and Python Connector code.