Stored Procedures
Introduction
Section titled “Introduction”Stored Procedures uses Snowflake’s Procedures API. The API consists of objects and the methods in those objects. You can create stored procedures, execute SQL via embedded scripts, and call these using Snowflake’s supported methods.
The methods that we support thus far are:
snowflake.execute()
snowflake.createStatement()
statement.execute()
resultSet.next()
resultSet.getColumnValue()
Getting started
Section titled “Getting started”This guide is designed for users new to Stored Procedures and assumes basic knowledge of Snowflake. Start LocalStack for Snowflake and execute Snowflake stored procedures.
JavaScript
Section titled “JavaScript”In LocalStack for Snowflake, you can create JavaScript Stored Procedures to define reusable logic using Snowflake’s JavaScript API. These procedures allow you to embed SQL execution inside JavaScript functions, enabling flexible control flow, conditionals, and result handling within your data workflows.
Creating a simple JavaScript procedure
Section titled “Creating a simple JavaScript procedure”The following is a simple JavaScript procedure that makes use of some of the most important methods of Snowflake JavasScript Procedures API:
CREATE OR REPLACE PROCEDURE minimal_proc()RETURNS STRINGLANGUAGE JAVASCRIPTAS$$ var stmt = snowflake.createStatement({sqlText: "SELECT 'hello world'"}); var rs = stmt.execute(); rs.next(); return rs.getColumnValue(1);$$;