SnowConvert AI - Redshift - CREATE PROCEDURE¶
Description¶
Creates a new stored procedure or replaces an existing procedure for the current database. (Redshift SQL Language Reference Create Procedure).
See the following definitions for more information about procedure clauses:
Grammar Syntax¶
The following is the SQL syntax to create a Procedure in Amazon Redshift. See the Redshift CREATE PROCEDURE specification for this syntax.
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
ALIAS DECLARATION¶
Description¶
If the stored procedure’s signature omits the argument name, you can declare an alias for the argument.
There is no support for this in Snowflake.
To achieve functional equivalence, aliases will be removed, and all usages will be renamed.
When an alias is declared for a parameter nameless, a generated name will be created for the parameter and the usages. When the alias is for a parameter with name the alias will be replaced by the real parameter name.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
ARGUMENTS MODE¶
Description¶
Amazon Redshift stored procedures support parameters that can be passed during procedure invocation. These parameters allow you to provide input values, retrieve output values, or use them for input and output operations. Below is a detailed explanation of the types of parameters, their modes, and examples of their usage. Snowflake only supports input values.
IN (Input Parameters)¶
Purpose: Used to pass values into the procedure.
Default Mode: If no mode is specified, parameters are considered IN.
Behavior: Values passed to the procedure cannot be modified inside the procedure.
OUT (Output Parameters)¶
Purpose: Used to return values from the procedure.
Behavior: Parameters can be modified inside the procedure and are returned to the caller. You cannot send an initial value.
INOUT (Input/Output Parameters)¶
Purpose: Used to pass values into the procedure and modify them to return updated values.
Behavior: Combines the behavior of IN and OUT. You must send an initial value regardless of the output.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs¶
SCC-EWI-0028 : Type not supported by Snowflake.
SSC-EWI-RS0010: Top-level procedure call with out parameters is not supported.
PROCEDURE BODY¶
Hint
SnowConvert does not support translation for PostgreSQL string constant definition in procedures. Use arrange option
Description¶
Like Redshift, Snowflake supports CREATE PROCEDURE using $$ procedure_logic $$ as the body. There is a difference in the Redshift syntax where a word can be inside the $$ like $word$ and used as a delimiter body like $word$ procedure_logic $word$. SnowConvert AI will transform it by removing the word, leaving the $$.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
BLOCK STATEMENT¶
Description¶
PL/pgSQL is a block-structured language. The complete body of a procedure is defined in a block, which contains variable declarations and PL/pgSQL statements. A statement can also be a nested block, or subblock.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
DECLARE¶
Description¶
Section to declare all the procedure variables except for loop variables.
Redshift supports multiple DECLARE sections per block statement, since Snowflake does not support this behavior they must be merged into a single declaration statement per block.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
EXCEPTION¶
Description¶
When an exception occurs, and you add an exception-handling block, you can write RAISE statements and most other PL/pgSQL statements. For example, you can raise an exception with a custom message or insert a record into a logging table.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
LABEL¶
Description¶
Labels are used in Redshift to qualify a block or to use the EXIT or END statement. Snowflake does not support labels.
Warning
Since labels are not supported in Snowflake, an EWI will be printed.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs¶
SSC-EWI-0094: Label declaration not supported
NONATOMIC¶
Description¶
The NONATOMIC commits after each statement in the stored procedure. Snowflake supports an AUTOCOMMIT parameter. The default setting for AUTOCOMMIT is TRUE (enabled).
While AUTOCOMMIT is enabled, Each statement outside an explicit transaction is treated as inside its implicit single-statement transaction. In other words, that statement is automatically committed if it succeeds and automatically rolled back if it fails. In other words, Snowflake works as NONATOMIC “by default”.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
POSITIONAL ARGUMENTS¶
Description¶
Redshift supports nameless parameters by referencing the parameters by their position using $. Snowflake does not support this behavior. To ensure functional equivalence, SnowConvert AI can convert those references by the parameter’s name if the name is present in the definition. If not, SnowConvert AI will generate a name for the parameter, and the uses will be replaced with the new name.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
RAISE¶
Description¶
Use the
RAISE levelstatement to report messages and raise errors.
Note
RAISE are fully supported by Snowflake.
Grammar Syntax¶
In Amazon Redshift, the RAISE statement is used to generate messages in the console or throw custom exceptions. Redshift allows you to specify different levels to indicate the severity of the message. In Snowflake, this functionality can be emulated using a user-defined function (UDF) that makes a call to the console depending on the specified level.
Exception:
When the level is “EXCEPTION”, a custom exception is raised with a general message: “To view the EXCEPTION MESSAGE, you need to check the log.” The exception code is-20002, which informs the user that the custom message can be found in the logs. This is due to limitations when sending custom exceptions in Snowflake.Warning:
If the level is “WARNING”,SYSTEM$LOG_WARNis used to print the warning message to Snowflake’s log, which helps highlight potential issues without interrupting the flow of execution.Info:
For any other level (such as “INFO”),SYSTEM$LOG_INFOis used to print the message to the console log, providing more detailed feedback about the system’s state without causing critical disruptions.
This approach allows emulating Redshift’s severity levels functionality, adapting them to Snowflake’s syntax and features, while maintaining flexibility and control over the messages and exceptions generated during execution.
Limitations
To view logs in Snowflake, it is necessary to have specific privileges, such as the
ACCOUNTADMINorSECURITYADMINroles.Logs in Snowflake are not available immediately and may have a slight delay before the information is visible.
Personalized error messages in exceptions are not displayed like in Redshift. To view custom messages, you must access the logs directly.
For further information, please refer to the following page.
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
UDFs ¶
RAISE_MESSAGE_UDF¶
STRING_FORMAT_UDF¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
RETURN¶
Description¶
The RETURN statement returns back to the caller from a stored procedure. (Redshift SQL Language Reference Return).
The conversion of the return statement from Amazon Redshift to Snowflake is straightforward, only considering adding a NULL to the return statement on Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Simple Case¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
When the procedure has out parameters¶
SnowConvert AI returns a variant with parameters set up as output parameters. So, for each return, SnowConvert AI will add a variant as a return value.
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
SECURITY (DEFINER | INVOKER)¶
Description¶
The SECURITY clause in Amazon Redshift stored procedures defines the access control and permissions context under which the procedure executes. This determines whether the procedure uses the privileges of the owner (creator) or the caller (user invoking the procedure).
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
VARIABLE DECLARATION¶
Description¶
Declare all variables in a block, except for loop variables, in the block’s DECLARE section.
Note
Variable declarations are fully supported by Snowflake.
Grammar Syntax¶
In Redshift, the CONSTANT keyword prevents variable reassignment during execution. Since Snowflake does not support this keyword, it is removed during transformation. This does not impact functionality, as the logic should not attempt to reassign a constant variable.
The NOT NULL constraint in Redshift ensures a variable cannot be assigned a null value and requires a non-null default value. As Snowflake does not support this constraint, it is removed during transformation. However, the default value is retained to maintain functionality.
A variable declare with a Refcursor is transformed to Resultset type, for more information.
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues ¶
No issues were found.
Related EWIs¶
SSC-FDM-PG0012: NOT NULL constraint has been removed. Assigning NULL to this variable will no longer cause a failure.
TRANSACTIONS¶
COMMIT¶
Description¶
Commits the current transaction to the database. This command makes the database updates from the transaction permanent. (Redshift SQL Language Reference COMMIT)
Grammar Syntax
Sample Source Patterns¶
Setup data¶
Redshift¶
Query¶
Snowflake¶
Query¶
COMMIT with TRANSACTION keyword¶
The TRANSACTION keyword is not supported in Snowflake. However, since it does not have an impact on functionality it will just be removed.
Redshift¶
Query¶
Snowflake¶
Query¶
COMMIT in a default transaction behavior procedure (without NONATOMIC clause)¶
To avoid out of scope transaction exceptions in Snowflake, the usages of COMMIT will be matched with BEGIN TRANSACTION.
When multiple COMMIT statements are present in the procedure, multiple BEGIN TRANSACTION statements will be generated after every COMMIT to emulate the Redshift transaction behavior.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
COMMIT in a procedure with NONATOMIC behavior¶
The NONATOMIC behavior from Redshift is emulated in Snowflake by using the session parameter AUTOCOMMIT set to true.
Since the AUTOCOMMIT session parameter is assumed to be true by SnowConvert AI, the COMMIT statement inside NONATOMIC procedures is left as is.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
1. COMMIT inside a nested procedure call
In Redshift, when a COMMIT statement is specified in a nested procedure call, the command will commit all pending work from previous statements in the current and parent scopes. Committing the parent scope actions is not supported in Snowflake, when this case is detected an FDM will be generated.
Redshift¶
Query¶
Snowflake¶
Query¶
Known Issues¶
There are no known issues.
Related EWIs¶
SSC-FDM-RS0006: Called procedure contains usages of COMMIT/ROLLBACK, modifying the current transaction in child scopes is not supported in Snowflake.
ROLLBACK¶
Description¶
Stops the current transaction and discards all updates made by that transaction. (Redshift SQL Language Reference ROLLBACK)
Grammar Syntax
Sample Source Patterns¶
Setup data¶
Redshift¶
Query¶
Snowflake¶
Query¶
ROLLBACK with TRANSACTION keyword¶
The TRANSACTION keyword is not supported in Snowflake. However, since it does not have an impact on functionality it will just be removed.
Redshift¶
Query¶
Snowflake¶
Query¶
ROLLBACK in a default transaction behavior procedure (without NONATOMIC clause)¶
To avoid out of scope transaction exceptions in Snowflake, the usages of ROLLBACK will be matched with BEGIN TRANSACTION.
When multiple transaction control statements are present in the procedure, multiple BEGIN TRANSACTION statements will be generated after every each one of them to emulate the Redshift transaction behavior.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
ROLLBACK in a procedure with NONATOMIC behavior¶
The NONATOMIC behavior from Redshift is emulated in Snowflake by using the session parameter AUTOCOMMIT set to true.
Since the AUTOCOMMIT session parameter is assumed to be true by SnowConvert AI, the ROLLBACK statement inside NONATOMIC procedures is left as is.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
1. ROLLBACK inside a nested procedure call
In Redshift, when a ROLLBACK statement is specified in a nested procedure call, the command will commit all pending work from previous statements in the current and parent scopes. Committing the parent scope actions is not supported in Snowflake, when this case is detected an FDM will be generated.
Redshift¶
Query¶
Snowflake¶
Query¶
2. ROLLBACK of DDL statements
In Snowflake, DDL statements perform an implicit commit whenever they are executed inside a procedure, making effective all the work before executing the DDL as well as the DDL itself. This causes the ROLLBACK statement to not be able to discard any changes before that point, this issue will be informed using an FDM.
Redshift¶
Query¶
Snowflake¶
Query¶
Known Issues¶
There are no known issues.
Related EWIs¶
SSC-FDM-RS0006: Called procedure contains usages of COMMIT/ROLLBACK, modifying the current transaction in child scopes is not supported in Snowflake.
SSC-FDM-RS0007: DDL statements perform an automatic COMMIT in Snowflake. ROLLBACK will not undo DDL-committed changes.
TRUNCATE¶
Description¶
Deletes all of the rows from a table without doing a table scan (Redshift SQL Language Reference TRUNCATE)
Grammar Syntax
Sample Source Patterns¶
Setup data¶
Redshift¶
Query¶
Snowflake¶
Query¶
TRUNCATE in a default transaction behavior procedure (without NONATOMIC clause)¶
Since the TRUNCATE statement automatically commits the transaction it is executed in, any of its usages will generate a COMMIT statement in Snowflake to emulate this behavior.
Since a COMMIT statement is generated the same BEGIN TRANSACTION statement generation will be applied to TRUNCATE. For more information check the COMMIT translation specification.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
TRUNCATE in a procedure with NONATOMIC behavior¶
The NONATOMIC behavior from Redshift is emulated in Snowflake by using the session parameter AUTOCOMMIT set to true.
Since the AUTOCOMMIT session parameter is assumed to be true by SnowConvert AI, the TRUNCATE statement inside NONATOMIC procedures is left as is, there is no need to generate a COMMIT statement because every statement is automatically committed when executed.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
1. TRUNCATE inside a nested procedure call
In Redshift, when a COMMIT statement is specified in a nested procedure call, the command will commit all pending work from previous statements in the current and parent scopes. Committing the parent scope actions is not supported in Snowflake, when this case is detected an FDM will be generated.
Redshift¶
Query¶
Snowflake¶
Query¶
Known Issues¶
There are no known issues.
Related EWIs¶
SSC-FDM-RS0006: Called procedure contains usages of COMMIT/ROLLBACK, modifying the current transaction in child scopes is not supported in Snowflake.
CONDITIONS¶
CASE¶
Description¶
The
CASEstatement in Redshift lets you return values based on conditions, enabling conditional logic in queries. It has two forms: simple and searched. (Redshift SQL Language Reference Conditionals: Case).
Simple Case¶
A simple CASE statement provides conditional execution based on equality of operands.
Note
Simple Case are fully supported by Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Searched Case¶
Note
Searched Case are fully supported by Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
CASE Without ELSE¶
In Redshift, when a CASE expression is executed and none of the validated conditions are met, and there is no ELSE defined, the exception ‘CASE NOT FOUND’ is triggered. In Snowflake, the code executes but returns no result. To maintain the same functionality in Snowflake in this scenario, an exception with the same name will be declared and executed if none of the CASE conditions are met.
Note
Case Without Else are fully supported by Snowflake.
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
IF¶
Description¶
This statement allows you to make decisions based on certain conditions. (Redshift SQL Language Reference Conditionals: IF).
SnowConvert AI will add the parenthesis in the conditions and change the keyword ELSIF by ELSEIF since Redshift does not require the parenthesis in the conditions and ELSIF is the keyword.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
LOOPS¶
Description¶
These statements are used to repeat a block of code until the specified condition. (Redshift SQL Language Reference Loops).
CONTINUE¶
Description¶
When the CONTINUE conditions are true, the loop can continue the execution, when is false stop the loop. (Redshift SQL Language Reference Conditionals: CONTINUE).
Warning
CONTINUE are partial supported by Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
Console Output |
|---|
1 |
2 |
3 |
4 |
6 |
7 |
Output Code:¶
Snowflake¶
Results¶
Console Output |
|---|
1 |
2 |
3 |
4 |
6 |
7 |
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
EXIT¶
Description¶
Stop the loop execution when the conditions defined in the WHEN statement are true (Redshift SQL Language Reference Conditionals: EXIT).
Warning
EXIT are partial supported by Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
FOR¶
Grammar Syntax¶
Integer variant
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
SSC-EWI-PG0006: Reference a variable using the Label is not supported by Snowflake.
LOOP¶
Description¶
A simple loop defines an unconditional loop that is repeated indefinitely until terminated by an EXIT or RETURN statement. (Redshift SQL Language Reference Conditionals: Simple Loop).
Warning
Simple Loop are partial supported by Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
WHILE¶
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
CURSORS¶
CLOSE CURSOR¶
Description¶
Closes all of the free resources that are associated with an open cursor.. (Redshift SQL Language Reference Close Cursor).
Note
This syntax is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
FETCH CURSOR¶
Description¶
Retrieves rows using a cursor. (Redshift SQL Language reference Fetch)
Transformation information
Sample Source Patterns¶
Setup data¶
Redshift¶
Query¶
Snowflake¶
Query¶
Fetch into¶
The FETCH into statement from Redshift is fully equivalent in Snowflake
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
1. Fetch without target variables is not supported
Snowflake requires the FETCH statement to specify the INTO clause with the variables where the fetched row values are going to be stored. When a FETCH statement is found in the code with no INTO clause an EWI will be generated.
Input Code:
Output Code:
Known Issues¶
There are no known issues.
Related EWIs¶
SSC-EWI-PG0015: Fetch cursor without target variables is not supported in Snowflake
OPEN CURSOR¶
Description¶
Before you can use a cursor to retrieve rows, it must be opened. (Redshift SQL Language Reference Open Cursor).
Note
This syntax is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Setup data¶
Redshift¶
Query¶
Snowflake¶
Query¶
Open cursor without arguments¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Open cursor with arguments¶
Cursor arguments have to be bound per each one of its uses, SnowConvert AI will generate the bindings, as well as reorder and repeat the passed values to the OPEN statement as needed to satisfy the bindings.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Open cursor with procedure parameters or local variables¶
The procedure parameters or local variables have to be bound per each one of its uses in the cursor query, SnowConvert AI will generate the bindings and add the parameter or variable names to the OPEN statement, even if the cursor originally had no parameters.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
DECLARE CURSOR¶
Description¶
Defines a new cursor. Use a cursor to retrieve a few rows at a time from the result set of a larger query. (Redshift SQL Language Reference Declare Cursor).
Note
This syntax is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.
DECLARE REFCURSOR¶
Description¶
A
refcursordata type simply holds a reference to a cursor. You can create a cursor variable by declaring it as a variable of typerefcursor
Note
Refcursor declarations are fully supported by Snowflake.
Grammar Syntax¶
Since Snowflake does not support the REFCURSOR data type, its functionality is replicated by converting the REFCURSOR variable into a RESULTSET type. The query used to open the REFCURSOR is assigned to the RESULTSET variable, after which a new cursor is created and linked to the RESULTSET variable. Additionally, all references to the original REFCURSOR within the cursor logic are updated to use the new cursor, thereby replicating the original functionality.
Sample Source Patterns¶
Case: Single use¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Case: Cursor with Dynamic Sql ¶
Input Code:¶
Redshift¶
Output Code:¶
Redshift¶
Case: Multiple uses: ¶
Input Code:¶
Redshift¶
Output Code:¶
Snowflake¶
Known Issues¶
There are no known issues.
Related EWIs.¶
There are no related EWIs.