Output parameter

General Description

Greenplum UDFs with output parameters are being transformed to Snowflake Stored Procedures, to maintain functional equivalence, due to Snowflake UDFs having some limitations executing DML (Data Manipulation Language) statements.

Since functions are being transformed into procedures, the transformation reference for PL/SQL also applies here.

Single out parameter

Greenplum

CREATE OR REPLACE FUNCTION functionSingleOutputParameter(OUT Message VARCHAR(100))
AS $$
BEGIN
  Message := 'Assignment value. Thanks!';
END;
$$ 
LANGUAGE PLPGSQL;

SELECT procedureLabelSingle();

CREATE OR REPLACE FUNCTION functionSQLSingleOutputParameter(param int, out min_len int)
    AS $$
        SELECT min(col1)
        FROM table1 
        WHERE col2 > param
    $$
    LANGUAGE SQL;

SELECT * FROM functionSQLSingleOutputParameter(0);

Snowflake Scripting

Multiple out parameter

Greenplum

Snowflake Scripting

Inside a procedure, the returned object can be easily deconstructed by using the following statements right after performing the procedure call: LET call_results VARIANT := (SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())));

var1 := GET(:call_results, 'Message');

var2 := GET(:call_results, 'Message2');

Known Issues

1. Out Parameters

Snowflake Scripting does not support OUT/INOUT parameters therefore these parameters are returned at the end of the procedure's body.

2. REFCURSOR Type not supported

In Snowflake, you can use stored procedures to execute SQL statements and return result sets, but the result sets are not returned as REFCURSOR objects. Instead, Snowflake supports returning result sets as tables, which can be queried and manipulated using SQL.

3. Missing name for the parameter

In Snowflake, all function parameters must have names, even if they also have data types.

4. Functions with parameterized queries are migrated to stored procedures in Snowflake

One of the main limitations of functions in Snowflake is that they do not allow the execution of parameterized queries within the function. That is why the use of stored procedures is made to emulate this functionality.

  1. MSC-GP0002: Non-returning Function translated to Stored Procedure.

  2. MSC-GP0003: Non-returning Function translated to Stored Procedure.

  3. MSCEWI1082: Auto-Generated code in order to support output parameters in Snowflake Scripting

  4. MSCEWI1083: Output parameters are not supported but their functionality is being emulated

Last updated

Was this helpful?