I am writing stored procedure in snowflake where i have several lines of select statements with multiple joins. So i need to use variable for each database schema. I tried experimenting with below code as an experiment but could not make it working. Can someone advise how to pass variable.
CREATE OR REPLACE PROCEDURE test_proc(tmpschema VARCHAR, dbschema VARCHAR)
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
AS
$$
/* Load STARTED */
try{
snowflake.createStatement({sqlText:`TRUNCATE TABLE '${dbschema}'.TAB1`}).execute();
snowflake.createStatement({sqlText:`TRUNCATE TABLE '${tmpschema}'.TAB2`}).execute();
}
catch(err){
return 'Failed Truncating TMP tables: ' + err;
}
$$
;
Procedure is being created successfully with above code, however calling is throwing an error.
call BIGDATA.test_proc('TMP', 'DB');
Error: Failed Truncating TMP tables:: ReferenceError: dbschema is not defined