Skip to content

Stored Procedures

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()

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.

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.

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 STRING
LANGUAGE JAVASCRIPT
AS
$$
var stmt = snowflake.createStatement({sqlText: "SELECT 'hello world'"});
var rs = stmt.execute();
rs.next();
return rs.getColumnValue(1);
$$;