I have some stored procedures that create tables that we use for validation purposes. Most of these tables get dropped on the procedure next execution.
I created these procedures and when I run them they run fine, but my problem is that now we want someone else to run those procedures, but they can't.
After some research, I found out that problem was that the stored procedure is trying to write into my schema, so since the users didn't have access to my scheme, they would get that insufficient privileges error.
Is there any way that the stored procedure would create tables into the scheme from where the stored procedure was called from rather than the schema belonging to whomever created the stored procedure?
Here is a small stored procedure I created for testing:
CREATE OR REPLACE PROCEDURE XXX.SP_TMP_TEST ()
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS
BEGIN
CALL XXX.SP_DROP_TABLE_IF_EXISTS ('TMP_TEST');
CREATE COLUMN TABLE TMP_TEST (TEST INTEGER);
END
GRANT EXECUTE ON XXX.SP_TMP_TEST TO USER_B;
Let's say USER_A creates this stored procedure in Schema XXX
Now every time USER_A calls it, table TMP_TEST gets created into USER_A schema.
Let's say USER_B tries to run it. They would get an error saying two tables with the same name can not exist. This is because the stored procedure to drop the table drops the table from USER_B's schema, but the create table tries to create the table on USER_A's schema.
The only way for this to work is to change SQL_SECURY TO DEFINER, but that would let USER_B create tables into USER_A's schema, and I want the tables to be created into USER_B's schema or USER_C or D, whoever calls the stored procedure.
I hope that makes sense.
Thanks in advance for your time and help.
Regards, Leonardo