How to run Python code without defining pernament/temporary User Defined Function or stored procedure?
The use case is to run the code one time inside a script and it should avoid creating/dropping additional database objects.
I am searching for an equivalent of anonymous block (SQL) known from Snowflake Scripting but for Python or other supported languages(Java, Scala).
Snowflake Scripting - Using an Anonymous Block
If you don’t want to store the block in a stored procedure in the database, you can define and use an anonymous block. An anonymous block is a block that is not part of a stored procedure. You define the block as a separate, standalone SQL statement.
The BEGIN … END statement that defines the block also executes the block. (You don’t run a separate CALL command to execute the block.)
Snowsight natively supports Notebooks:
Writing Snowpark Code in Python Worksheets
Write Snowpark code in Python worksheets to process data using Snowpark Python in Snowsight. By writing code in Python worksheets, you can perform your development and testing in Snowflake without needing to install dependent libraries.
To develop with Python worksheets, do the following:
- Prepare roles and packages in Snowflake.
- Set up your worksheet for development.
- Write Snowpark code in your Python worksheet.
- Run your Python worksheet.
If we check query history, the CALL(with Anonymous Procedure)
is still used:
When development is done, the code can be deployed as a stored procedure.
Related: Creating a Python Stored Procedure to Automate Your Python Worksheet Code