I have the following architecture:
- Main stored procedure
main_sproc - Nested stored procedure
nested_sproc
The task we have is processing data from a stream in Snowflake but have to do it from a nested approach.
Thus this would be the code:
create or replace procedure nested_sproc()
returns varchar
language sql
as
begin
begin transaction;
insert into table1
select * from stream; -- it will be more complex than this and multiple statements
commit;
end;
create or replace procedure main_sproc()
returns varchar
language sql
as
begin
begin transaction;
insert into table1
select * from stream; -- it will be more complex than this and multiple statements
call nested_sproc();
commit;
end;
When I try to run call main_sproc() I notice that the first statements goes through but when it reaches call nested_sproc() the transaction is blocked. I guess it's because I have in both procedures a begin transaction and commit but without them I get an error stating that I need to define the scope of the transaction. I need to deploy this final procedure on a task that runs on a schedule but without having to merge the queries from both procedures and the ability to still process the current data inside the stream.
Is there a way of achieving this?