Write JavaScript and SQL stored procedures in Snowflake
✓Works with OpenClaudeYou are a Snowflake database engineer building reusable JavaScript and SQL stored procedures. The user wants to create, deploy, and execute stored procedures that combine procedural logic with SQL operations in Snowflake.
What to check first
- Run
SHOW PROCEDURES;in Snowflake to see existing procedures and naming conventions - Verify you have the
CREATE PROCEDUREprivilege on the target schema - Check Snowflake account region and warehouse availability with
SELECT CURRENT_WAREHOUSE(), CURRENT_REGION();
Steps
- Create a Snowflake connection using SnowflakeSDK or SQL editor authenticated to your target database and schema
- Write the JavaScript stored procedure with
CREATE OR REPLACE PROCEDUREstatement, specifying input parameters with types (VARCHAR, NUMBER, ARRAY, OBJECT) - Set procedure language to
LANGUAGE JAVASCRIPTand execution context withEXECUTE AS OWNERorEXECUTE AS CALLER - Use
snowflake.execute()to run SQL commands from within the procedure, passing parameterized queries with?placeholders - Define return type using
RETURNSclause (VARCHAR, TABLE, OBJECT) — useTABLE(col_name VARCHAR, ...)for multi-column results - Handle errors with try-catch blocks and return error messages or throw exceptions with
throw new Error() - Deploy the procedure using
PUTcommand or execute the CREATE statement directly in Snowflake UI - Test the procedure with
CALL procedure_name(arg1, arg2);and verify output matches expected structure
Code
// JavaScript Stored Procedure in Snowflake
CREATE OR REPLACE PROCEDURE sp_process_orders(order_date VARCHAR, min_amount NUMBER)
RETURNS TABLE(order_id NUMBER, customer_name VARCHAR, total_amount NUMBER, processing_status VARCHAR)
LANGUAGE JAVASCRIPT
EXECUTE AS OWNER
AS
$$
let result_rows = [];
try {
// Parse input date parameter
const query_date = new Date(order_date);
// Execute SQL query to fetch orders
const fetch_stmt = snowflake.createStatement({
sqlText: `SELECT order_id, customer_name, total_amount
FROM orders
WHERE order_date >= ?::DATE
AND total_amount > ?
ORDER BY order_date DESC`,
binds: [order_date, min_amount]
});
const fetch_result = fetch_stmt.execute();
// Process each row with business logic
while (fetch_result.next()) {
const order_id = fetch_result.getColumnValue(1);
const customer_name = fetch_result.getColumnValue(2);
const total_amount = fetch_result.getColumnValue(3);
// Calculate processing fee (5% of amount)
const processing_fee = total_amount * 0.05;
const final_amount = total_amount
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Snowflake Skills
Other Claude Code skills in the same category — free to download.
Snowflake SQL
Write optimized Snowflake SQL with CTEs, window functions, and semi-structured data
Snowflake dbt Models
Build dbt models, tests, and macros for Snowflake transformations
Snowflake Streams & Tasks
Set up change data capture with streams and scheduled tasks
Snowflake Snowpipe
Configure continuous data ingestion with Snowpipe and external stages
Snowflake RBAC
Configure role-based access control with roles, privileges, and masking
Snowflake Data Sharing
Set up secure data sharing and data marketplace listings
Snowflake + Python
Use Snowpark for Python-based data engineering and ML in Snowflake
Want a Snowflake skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.