0

I have a javascript stored procedure which creates a temporary table inside it using the CTAS syntax to hold some temporary results during computation. I want to be able to call this stored procedure inside a transaction. Is this not allowed?

CREATE PROCEDURE my_stored_proc()
RETURNS BOOLEAN NOT NULL 
LANGUAGE javascript 
EXECUTE AS CALLER
AS 
$$
    ...
    var stmt = snowflake.createStatement(
        {sqlText: "CREATE TEMPORARY TABLE temp_table..."}
        );
    var rs = stmt.execute();
    ...
$$;

BEGIN;
...
CALL my_stored_proc();
...
COMMIT;

I tried to wrap this stored proc with a transaction but it commits as soon as the stored proc completes, I want to be able to rollback the statements if there is an error thrown by the stored proc during execution.

1 Answer 1

0

Remember that DDL statements (CREATE TABLE, etc.) cause an implicit COMMIT. Such statements should not be used inside a stored procedure if the procedure will be called inside a transaction.

https://docs.snowflake.com/en/sql-reference/stored-procedures-usage.html#transaction-management

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.