I am trying to create a stored procedure with Snowflake Scripting specifically to query a user table and then iterate through the results and alter those users.
Here is what I have so far:
create or replace procedure TEST_PROCEDURE()
returns varchar
language sql
as
$$
declare
c1 CURSOR for SELECT 'USERNAME@EMAIL.COM' AS NAME;
user_name varchar;
begin
for record in c1 do
user_name := record.name;
ALTER USER user_name SET DEFAULT_ROLE = 'REPORTER', DEFAULT_WAREHOUSE = 'REPORTING_WH_L';
end for;
return user_name;
end;
$$
;
When I run the stored procedure I get the following error:
Uncaught exception of type 'STATEMENT_ERROR' on line 8 at position 9: SQL compilation error: User 'USER_NAME' does not exist or not authorized.
I changed USERNAME@EMAIL.COM just for this question it is querying a table and returning valid Snowflake user names.
The query history is showing that within the ALTER USER command it is not replacing user_name with the result from the cursor.
Any ideas on how to fix this?