I have a use case in snowflake procedure, where I have two databases with different roles. I want to insert data in tables of both these databases from one stored procedure. I created procedure in one of the database and procedure is inserting data in that database but when I tried to insert in second database it says:
SQL compilation error: Database 'SecondDB' does not exist or not authorized.
Then I tried to use query before inserting in second database within procedure to change role like this:
var SwitchToLoader = "use role SecondDbRole";
try {
snowflake.execute
(
{sqlText: SwitchToLoader}
);
}
catch (err) {
return "Failed: " + err;
}
this is still give me error:
SQL access control error: Insufficient privileges to operate on role 'SecondDbRole'
So any suggestions how to insert data in my second database that has different role from single stored procedure?