I am trying to create a stored procedure in snowflake for generating snow pipes, i have the sql needed, the issue I'm having is now wrappping that sql in a procedure we can call and pass in values like the db name and table name.
when I try to pass these values into the procedure I get an erorr saying "Uncaught ReferenceError: db_name is not defined in EXECUTE_SQL_COMMAND"
code:
create or replace procedure execute_sql_command(db_name varchar,tbl_name varchar)
returns string
language javascript
as
$$
var target_database = db_name;
var target_table = tbl_name;
var sql_string =
"select concat(rtrim('CREATE OR REPLACE PIPE ','" + target_database + "'));";
var res = snowflake.createStatement({sqlText: sql_string});
var ex = res.execute();
ex.next();
var query_value = ex.getColumnValue(1);
return query_value.toString();
$$;
call execute_sql_command('dev_stage_db','miattr');