RETURN (Snowflake Scripting)¶
Returns the value of a specified expression.
For more information about returning values, see Returning a value.
Note
This Snowflake Scripting construct is valid only within a Snowflake Scripting block.
Syntax¶
Where:
expressionAn expression that evaluates to the value to return.
Usage notes¶
A RETURN statement can be run in:
A block in a stored procedure or Snowflake Scripting user-defined function (UDF).
An anonymous block.
A RETURN statement returns one of the following types:
A table. Use
TABLE(...)in theRETURNstatement.If your block is in a stored procedure, you must also specify the
RETURNS TABLE...clause in the CREATE PROCEDURE statement.Note
Currently, in the
RETURNS TABLE(...)clause, you can’t specify GEOGRAPHY as a column type. This applies whether you are creating a stored or anonymous procedure.If you attempt to specify GEOGRAPHY as a column type, calling the stored procedure results in the error:
To work around this issue, you can omit the column arguments and types in
RETURNS TABLE().If you want to return the data that a RESULTSET points to, pass the RESULTSET to TABLE(…), as shown in the example below:
You can set a variable to the return value of a stored procedure. For more information, see Using the value returned from a stored procedure call.
Examples¶
This example declares a variable named my_var for use in a Snowflake Scripting anonymous block and
then returns the value of the variable:
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_stream or execute_string method in Python Connector
code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):