ALTER SESSION SET QUERY_TAG = ‘” <<CRM_VERIFY_TAG>>”;
But what about, if we need to set this parameter via stored procedure, Will Developing the procedure with Owner Rights allows to successful execution of proc. Lets see.
Owner’s rights stored procedures are not permitted to change session state.
In order to make it works and set the SESSION parameter inside the Stored Procedure we need to define the procedure as CALLER.
create or replace procedure get_query_tag(BATCH_ID varchar)
execute as caller
var row_count = 0;
var tag = BATCH_ID + "_VERIFY_TAG";
var sql_session = "ALTER SESSION SET QUERY_TAG = '" + tag + "'";
var sql_command = "select count(*) from customers";
var qstmt = snowflake.createStatement(
var stmt = snowflake.createStatement(
var res = stmt.execute();
// Get back the row count. Specifically, …
// … first, get the first (and in this case only) row from the
// result set …
// … then extract the returned value (which in this case is the
// number of rows in the table).
row_count = res.getColumnValue(1);
If a caller’s rights stored procedure makes changes to the session, those changes can persist after the end of the
So we can see Caller’s Rights and Owner’s Rights significance inside the Stored Procedures.