Skip to content

Commit 5d1102f

Browse files
docs: Snowflake JavaScript Stored Procedures (#134)
Co-authored-by: Gentris Leci <lecigentris@gmail.com>
1 parent 92e286f commit 5d1102f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Stored Procedures
3+
description: Get started with Stored Procedures in LocalStack for Snowflake
4+
tags: ["Base"]
5+
---
6+
7+
## Introduction
8+
9+
Stored Procedures uses [Snowflake's Procedures API](https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-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.
10+
11+
The methods that we support thus far are:
12+
- `snowflake.execute()`
13+
- `snowflake.createStatement()`
14+
- `statement.execute()`
15+
- `resultSet.next()`
16+
- `resultSet.getColumnValue()`
17+
18+
## Getting started
19+
20+
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](https://docs.snowflake.com/en/developer-guide/stored-procedure/stored-procedures-api#object-snowflake).
21+
22+
## JavaScript
23+
24+
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.
25+
26+
### Creating a simple JavaScript procedure
27+
28+
The following is a simple JavaScript procedure that makes use of some of the most important methods of Snowflake JavasScript Procedures API:
29+
30+
```javascript showLineNumbers
31+
CREATE OR REPLACE PROCEDURE minimal_proc()
32+
RETURNS STRING
33+
LANGUAGE JAVASCRIPT
34+
AS
35+
$$
36+
var stmt = snowflake.createStatement({sqlText: "SELECT 'hello world'"});
37+
var rs = stmt.execute();
38+
rs.next();
39+
return rs.getColumnValue(1);
40+
$$;
41+
```

0 commit comments

Comments
 (0)