Snowflake Scripting Developer Guide¶
Snowflake Scripting is an extension to Snowflake SQL that adds support for procedural logic. You can use Snowflake Scripting syntax in stored procedures and user-defined functions (UDFs). You can also use Snowflake Scripting syntax outside of stored procedures and UDFs and stored procedures. The next topics explain how to use Snowflake Scripting.
- Understanding blocks in Snowflake Scripting
Learn the basic structure of Snowflake Scripting code.
- Working with variables
Declare and use variables.
- Returning a value
Return values from stored procedures and an anonymous block.
- Working with conditional logic
Control flow with IF and CASE statements.
- Working with loops
Control flow with FOR, WHILE, REPEAT, and LOOP.
- Working with cursors
Iterate through query results with a cursor.
- Working with RESULTSETs
Iterate over the result set returned by a query.
- Handling exceptions
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.