This article is about the current transformation of the output parameters and how their functionality is being emulated.
Some parts in the output code are omitted for clarity reasons.
Description
An output parameter is a parameter whose value is passed out of the stored procedure, back to the calling SQL block. Since the output parameters are not supported by Snowflake Scripting, a solution has been implemented in order to emulate their functionality.
Sample Source Patterns
Single OUT parameter
The most basic scenario for OUT parameters is when the procedure only has one. In this case, we simply return the OUT parameter at the end of the procedure body.
The EXEC procedure has to be translated as well, for this a CALL is created, the parameters are passed without any modifier ("OUT" is removed), and subsequently, an assignment is done so the parameter is associated with it's respective resulting value.
SQL Server
IN -> SqlServer_01.sql
-- Procedure with output parameterCREATEPROCEDURE dbo.outmain@name VARCHAR (255) OUTPUTASSET @name ='Jane';-- Auxiliary procedure that calls the main procedureCREATEPROCEDURE dbo.outauxASDECLARE @name VARCHAR (255);EXEC dbo.outmain @name = @name OUTPUT;
Snowflake Scripting
OUT -> SqlServer_01.sql
-- Procedure with output parameterCREATEORREPLACEPROCEDURE dbo.outmain (NAME STRING)RETURNSVARCHARLANGUAGESQLCOMMENT ='{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},{"attributes":{"component":"transact"}}'EXECUTEASCALLERAS$$BEGINNAME :='Jane';-- Auxiliary procedure that calls the main procedure !!!RESOLVE EWI!!! /*** SSC-EWI-0073 - PENDING FUNCTIONAL EQUIVALENCE REVIEW FOR 'CREATE PROCEDURE' NODE ***/!!!CREATEPROCEDURE dbo.outauxASDECLARE @name VARCHAR (255);EXEC dbo.outmain @name = @name OUTPUT;RETURNNAME;END;$$;
Multiple OUT parameters
When more than one OUT parameters are found, the RETURNS clause of the procedure changes to VARIANT. This is to accommodate the OBJECT_CONSTRUCT that is going to be used to store the values of the OUT parameters.
On top of that, a RETURN statement is added to the end of the procedure's body. This is where the OBJECT_COSNTRUCT is created and all the OUT parameter values are stored within it. This object will then be used by the caller to assign the parameters value to the corresponding result.
SQL Server allows procedures to have return values. When a procedure has both a return value and OUT parameter(s), a similar approach to the Multiple OUT parameters scenario is followed. The original return value is treated as an OUT parameter would be treated, so it's stored within the OBJECT_CONSTRUCT and extracted inside the caller procedure.
SQL Server
IN -> SqlServer_03.sql
-- Procedure with multiple output parametersCREATEPROCEDURE dbo.outmain@name VARCHAR (255) OUTPUTASSET @name ='Jane';RETURN0;-- Auxiliary procedure that calls the main procedureCREATEPROCEDURE dbo.outauxASDECLARE @name VARCHAR (255);DECLARE @returnValue INT;EXEC @returnValue = dbo.outmain @name = @name OUTPUT;