SnowConvert AI - Teradata - SQL to Snowflake Scripting (Procedures)¶
ABORT and ROLLBACK¶
Translation reference to convert Teradata ABORT and ROLLBACK statements to Snowflake Scripting
Description ¶
Teradata’s ABORT and ROLLBACK statements are replaced by a ROLLBACK statement in Snowflake Scripting.
Sample Source Patterns ¶
Basic ABORT and ROLLBACK¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Conditional ABORT and ROLLBACK¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
ABORT and ROLLBACK with table references and FROM clause¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
ABORT and ROLLBACK with table references without FROM clause¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Abort and rollback¶
Known Issues¶
1. Custom Error Message¶
Even though the ROLLBACK AND ABORT are supported, using them with a custom error message is not supported.
Teradata ¶
Error message¶
Snowflake Scripting ¶
Error message¶
2. Aggregate function¶
The use of the aggregate function combined with ABORT/ROLLBACK is not supported
Teradata ¶
Aggregate function¶
Snowflake Scripting ¶
Aggregate function¶
ACTIVITY_COUNT¶
Translation specification for the ACTIVITY_COUNT status variable.
Description¶
The ACTIVITY_COUNT status variable returns the number of rows affected by an SQL DML statement in an embedded SQL or stored procedure application. For more information, see the Teradata ACTIVITY_COUNT documentation.
There is no direct equivalent in Snowflake. However, there is a workaround to emulate the ACTIVITY_COUNT’s behavior. One must simply use the following query:
This query retrieves and returns the first column of the result set from the last executed query in the current session. Furthermore, $1 can be replaced by "number of rows inserted", "number of rows updated" or "number of rows deleted" based on the query type.
As expected, this translation behaves like its Teradata counterpart only when no other queries besides the SQL DML statement are executed before calling LAST_QUERY_ID.
Sample Source Patterns¶
Setup data¶
Teradata¶
Query¶
Snowflake¶
Query¶
Supported usage¶
Teradata¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
If
ACTIVITY_COUNTis called twice or more times before executing a DML statement, the transformation might not return the expected values. See SSC-FDM-TD0033.If
ACTIVITY_COUNTis called after a non DML statement was executed, the transformation will not return the expected values. See SSC-FDM-TD0033.ACTIVITY_COUNTrequires manual fixing when inside aSELECT/SET INTO VARIABLEstatement and was not able to be identified as a column name. See SSC-EWI-TD0003.
Related EWIs¶
SSC-FDM-TD0033: ‘ACTIVITY_COUNT’ TRANSFORMATION MIGHT REQUIRE MANUAL ADJUSTMENTS.
BEGIN END¶
Translation reference to convert Teradata BEGIN END clause to Snowflake Scripting
BEGIN END TRANSACTION¶
Description¶
Defines the beginning of an explicit logical transaction in Teradata session mode.
For more information, see the Teradata BEGIN END Transaction documentation.
Sample Source Pattern ¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
BEGIN END REQUEST¶
Description¶
Delimits a SQL multistatement request
For more information, see the Teradata BEGIN END Request documentation.
Sample Source Pattern ¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
BEGIN END COMPOUND¶
Description¶
Delimits a compound statement in a stored procedure.
For more information, see the Teradata BEGIN END Compound documentation.
Sample Source Pattern ¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Known Issues¶
1. Labels not supported in outer BEGIN END blocks¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Related EWIs¶
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
CASE¶
Translation reference to convert Teradata CASE statement to Snowflake Scripting
Description ¶
Provides conditional execution of statements based on the evaluation of the specified conditional expression or equality of two operands.
The CASE statement is different from the SQL CASE expression_,_ which returns the result of an expression.
For more information, see the Teradata CASE documentation.
Sample Source Patterns ¶
Sample auxiliary table¶
Teradata¶
Snowflake¶
Simple Case¶
Teradata¶
Query¶
Result¶
Snowflake Scripting¶
Query¶
Result¶
Searched Case¶
Teradata¶
Query¶
Result¶
Snowflake Scripting¶
Query¶
Result¶
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
CURSOR¶
Translation reference to convert Teradata CURSOR statement to Snowflake Scripting
Description ¶
A cursor is a data structure that is used by stored procedures at runtime to point to a resultset returned by an SQL query. For more information, see the Teradata SQL Cursor Control and DML Statements documentation.
Sample Source Patterns ¶
Setup Data¶
The following code is necessary to execute the sample patterns present in this section.
Teradata¶
Snowflake¶
Basic Cursor¶
Teradata¶
Cursor Code¶
Result¶
Snowflake Scripting¶
Cursor Code¶
Result¶
Single Returnable Cursor¶
The following procedure is intended to return one result set since it has the DYNAMIC RESULT SETS 1 property in the header, the cursor has the WITH RETURN property and is being opened in the body.
Teradata¶
Cursor Code¶
Result¶
Snowflake Scripting¶
Cursor Code¶
Result¶
Multiple Returnable Cursors¶
The following procedure is intended to return multiple results when DYNAMIC RESULT SETS property in the header is greater than 1, the procedure has multiple cursors with the WITH RETURN property and these same cursors are being opened in the body.
Teradata¶
Cursor Code¶
Result¶
Snowflake Scripting¶
Cursor Code¶
Results¶
Cursors With Binding Variables¶
The following cursor uses binding variables as the were condition to perform the query.
Teradata¶
Cursor Code¶
Result¶
Snowflake Scripting¶
Cursor Code¶
Result¶
Cursor For Loop¶
It is a type of loop that uses a cursor to fetch rows from a SELECT statement and then performs some processing on each row.
Teradata¶
Cursor Code¶
Result¶
Snowflake Scripting¶
Cursor Code¶
Result¶
Cursor Fetch inside a Loop¶
It allows one to retrieve rows from a result set one at a time and perform some processing on each row.
Teradata¶
Cursor Code¶
Result¶
Snowflake Scripting¶
Cursor Code¶
Result¶
Known Issues¶
The following parameters are not applicable in Snowflake Scripting.
1. Declare¶
[ SCROLL/NO SCROLL ] Snowflake Scripting only supports FETCH NEXT.
[ READ-ONLY ] This is the default in Snowflake Scripting.
[ UPDATE ].
2. Fetch¶
[ NEXT ] This is the default behavior in Snowflake Scripting.
[ FIRST ].
Related EWIs¶
SSC-FDM-0020: Multiple result sets are returned in temporary tables.
SSC-PRF-0003: Fetch inside a loop is considered a complex pattern, this could degrade Snowflake performance.
SSC-PRF-0004: This statement has usages of cursor for loop.
DECLARE CONTINUE HANDLER¶
Translation reference to convert Teradata DECLARE CONTINUE handler to Snowflake Scripting
Description ¶
Handle completion conditions and exception conditions not severe enough to affect the flow of control.
For more information, see the Teradata DECLARE CONTINUE handler documentation.
Sample Source Patterns ¶
DECLARE CONTINUE HANDLER¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Known Issues¶
DECLARE CONTINUE HANDLER FOR SQLSTATE¶
The support of declaring continue handlers for some SQLSTATE values is not currently supported by Snowflake Scripting.
Teradata ¶
Query¶
Snowflake Scripting ¶
Related EWIs¶
SSC-EWI-TD0004: Not supported SQL Exception on continue handler.
DECLARE CONDITION HANDLER¶
Translation reference to convert Teradata DECLARE CONDITION handler to Snowflake Scripting
Description ¶
Assign a name to an SQLSTATE code, or declare a user-defined condition.
For more information, see the Teradata DECLARE CONDITION handler documentation.
Sample Source Patterns ¶
DECLARE CONDITION¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Known Issues¶
DECLARE CONDITION FOR SQLSTATE¶
The support of declaring conditions for SQLSTATE values is not currently supported by Snowflake Scripting.
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Related EWIs¶
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
DECLARE¶
Translation reference to convert Teradata DECLARE statement to Snowflake Scripting
Description ¶
Declares one or more local variables.
For more information, see the Teradata DECLARE documentation.
Sample Source Patterns ¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
DML and DDL Objects¶
Description ¶
DML and DDL objects are translated in the same way regardless of whether they are inside stored procedures or not. For further information check the following links.
Translation References¶
data-types.md: Compare Teradata data types and their equivalents in Snowflake.
ddl: Explore the translation of the Data Definition Language.
dml: Explore the translation of the Data Manipulation Language.
built-in-functions: Compare functions included in the runtime of both languages.
EXCEPTION HANDLERS¶
Translation reference to convert Teradata EXCEPTION HANDLERS clause to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
Teradata’s single and multiple Exception Handlers are replaced by its equivalent handlers in Snowflake Scripting.
For more information, see the Teradata EXCEPTION HANDLERS documentation.
Sample Source Patterns ¶
SQLEXCEPTION HANDLER¶
Teradata ¶
Single handler¶
Multiple handlers¶
Snowflake Scripting ¶
Single handler¶
Multiple handlers¶
User-Defined Handlers¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Known Issues¶
CONTINUE Handler¶
Danger
A ‘CONTINUE’ handler in Teradata allows the execution to be resumed after executing a statement with errors. This is not supported by the exception blocks in Snowflake Scripting. Condition Handler Teradata reference documentation.
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Other not supported handlers¶
Danger
Handlers for SQLSTATE, SQLWARNING, and NOT FOUND are not supported
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Related EWIs¶
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
SSC-EWI-TD0004: Not supported SQL Exception on continue handler.
EXECUTE/EXEC¶
Translation reference to convert Teradata EXECUTE or EXEC statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
The Teradata EXECUTEstatement allows the execution prepared dynamic SQL or macros, on the other hand exec only allows macros.
For more information regarding Teradata EXECUTE/EXEC, check Macro Form and Dynamic SQL Form
Sample Source Patterns ¶
Setup data¶
The following code is necessary to execute the sample patterns present in this section.
Teradata¶
Snowflake¶
Execute prepared statement¶
Teradata¶
Execute¶
Snowflake Scripting ¶
Execute¶
Execute macro statement¶
Teradata¶
Execute¶
Result¶
Snowflake Scripting ¶
Execute¶
Related EWIs¶
SSC-EWI-0030: The statement below has usages of dynamic SQL.
SSC-EWI-0073: Pending Functional Equivalence Review.
EXECUTE IMMEDIATE¶
Translation reference to convert Teradata EXECUTE IMMENDIATE statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
The Teradata EXECUTE IMMEDIATE statement allows the execution of dynamic SQL contained on variables or string literals.
For more information, see the Teradata EXECUTE IMMEDIATE documentation.
Sample Source Patterns ¶
Setup data¶
The following code is necessary to execute the sample patterns present in this section.
Teradata¶
Snowflake¶
Execute Example ¶
Teradata ¶
Query¶
Result¶
Snowflake Scripting ¶
Query¶
Result¶
Result¶
Related EWIs¶
SSC-EWI-0030: The statement below has usages of dynamic SQL.
FUNCTION OPTIONS OR DATA ACCESS¶
Note
Some parts in the output code are omitted for clarity reasons.
Note
Non-relevant statement.
Warning
Notice that this statement isremoved from the migrationbecause it is a non-relevant syntax. It means that it is not required in Snowflake.
Description¶
Functions options or data access options are statements used in functions on the declaration part to specify certain characteristics. These can be:
CONTAINS SQLSQL SECURITY DEFINERCOLLATION INVOKERSPECIFIC FUNCTION_NAME
Sample Source Patterns¶
Function Options¶
Notice that in this example the function options have been removed because they are not required in Snowflake.
Teradata¶
Snowflake¶
Known Issues ¶
No issues were found.
Related EWIs ¶
No related EWIs.
GET DIAGNOSTICS EXCEPTION¶
Translation reference to convert Teradata GET DIAGNOSTICS EXCEPTION statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
GET DIAGNOSTICS retrieves information about successful, exception, or completion conditions from the Diagnostics Area.
For more information, see the Teradata GET DIAGNOSTICS documentation.
Sample Source Patterns ¶
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Known Issues¶
CLASS_ORIGIN, CONDITION_NUMBER¶
Danger
The use of GET DIAGNOSTICS for CLASS_ORIGIN, CONDITION_NUMBER is not supported
Teradata ¶
Query¶
Snowflake Scripting ¶
Query¶
Related EWIs¶
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
IF¶
Translation reference to convert Teradata IF statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
Provides conditional execution based on the truth value of a condition.
For more information, see the Teradata IF documentation.
Sample Source Patterns ¶
Sample auxiliary table¶
Teradata¶
Snowflake¶
Possible IF variations¶
Teradata ¶
Code 1¶
Code 2¶
Code 3¶
Code 4¶
Result 1¶
Result 2¶
Result 3¶
Result 4¶
Snowflake Scripting¶
Query 1¶
Query 2¶
Query 3¶
Query 4¶
Result 1¶
Result 2¶
Result 3¶
Result 4¶
Known Issues ¶
No issues were found.
Related EWIs ¶
No related EWIs.
LOCKING FOR ACCESS¶
Note
Some parts in the output code are omitted for clarity reasons.
Note
Non-relevant statement.
Warning
Notice that this statement isremoved from the migrationbecause it is a non-relevant syntax. It means that it is not required in Snowflake.
Description¶
The functionality of locking a row in Teradata is related to the access and the privileges. Revire the following documentation to know more.
Sample Source Patterns¶
Locking row¶
Notice that in this example the LOCKING ROW FOR ACCESS has been deleted. This is because Snowflake handles accesses with roles and privileges. The statement is not required.
Teradata¶
Snowflake¶
Known Issues ¶
No issues were found.
Related EWIs¶
SSC-FDM-0001: Views selecting all columns from a single table are not required in Snowflake.
SSC-FDM-0007: Element with missing dependencies.
LOOP¶
Translation reference to convert Teradata LOOP statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
Teradata’s LOOP statement is translated to Snowflake Scripting LOOP syntax.
For more information, see the Teradata LOOP documentation.
Sample Source Patterns ¶
Teradata ¶
Loop¶
Result¶
Snowflake Scripting ¶
Loop¶
Result¶
Known Issues ¶
No issues were found.
Related EWIs ¶
No related EWIs.
OUTPUT PARAMETERS¶
This article is about the current transformation of the output parameters and how their functionality is being emulated.
Note
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 statement. Snowflake has direct support for output parameters.
Sample Source Patterns¶
Single out parameter¶
Teradata¶
Snowflake¶
Multiple out parameter¶
Teradata¶
Snowflake¶
Related EWIs ¶
No related EWIs.
PREPARE¶
Translation specification to convert Teradata PREPARE statement to Snowflake Scripting. This section review the PREPARE pattern related to a cursor logic.
Description ¶
Prepares the dynamic DECLARE CURSOR statement to allow the creation of different result sets. Allows dynamic parameter markers.
For more information, please review the following documentation.
Teradata syntax:
Where:
statement_name is the same identifier as
statement_namein a DECLARE CURSOR statement.statement_string is the SQL text that is to be executed dynamically.
statement_string_variable is the name of an SQL local variable, or an SQL parameter or string variable, that contains the SQL text string to be executed dynamically.
Note
Important information
For this transformation, the cursors are renamed since they cannot be dynamically updated.
Sample Source Patterns ¶
Data setting for examples¶
For this example, please use the following complementary queries in the case that you want to run each case.
Teradata¶
Snowflake¶
Simple scenario¶
This example reviews the functionality for the cases where a single cursor is being used one single time.
Teradata ¶
Query¶
Output¶
Col1 |
|---|
1 |
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Col1 |
|---|
1 |
Simple scenario with RETURN ONLY¶
Teradata ¶
Query¶
Output¶
Col1 |
|---|
1 |
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Col1 |
|---|
1 |
Reused cursor case¶
Teradata ¶
Query¶
Output¶
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Modified query before usage¶
Teradata ¶
Query¶
Output¶
Col1 |
|---|
1 |
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Col1 |
|---|
1 |
Simple cursor combined with no PREPARE pattern¶
Teradata ¶
Query¶
Output¶
Col1 |
|---|
1 |
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Col1 |
|---|
1 |
Prepare combined with nested cursors¶
Teradata ¶
Query¶
Output¶
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Variable markers without variable reordering¶
Warning
This case is not supported yet.
Teradata ¶
Query¶
Output¶
Col1 |
|---|
ok |
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Col1 |
|---|
ok |
Variable markers with variable reordering¶
Warning
This case is not supported yet.
Note
When there are variables setting the value into different ones between the PREPARE statement and OPEN cursor in Teradata, It is necessary to move this variable before the EXECUTE IMMEDIATE in Snowflake. So, the dynamic variable information is updated at the moment of running the dynamic query.
Teradata ¶
Query¶
Output¶
Snowflake Scripting ¶
Note
Usages for cursors must be renamed and declared again.
Query¶
Output¶
Anonymous blocks - Declaration outside the block¶
Warning
This case is not supported yet.
Teradata ¶
Query¶
Output¶
Query¶
Output¶
Known Issues¶
Review carefully nested cursors and conditionals, if that is the case.
Related EWIs ¶
No related EWIs.
REPEAT¶
Translation reference to convert Teradata REPEAT statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
Teradata’s REPEAT statement is translated to Snowflake Scripting REPEAT syntax.
For more information, see the Teradata REPEAT documentation.
Sample Source Patterns ¶
Teradata ¶
Repeat¶
Result¶
Snowflake Scripting ¶
Repeat¶
Result¶
Known Issues ¶
No issues were found.
Related EWIs ¶
No related EWIs.
SET¶
Translation reference to convert Teradata SET statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
Assigns a value to a local variable or parameter in a stored procedure.
For more information, see the Teradata SET documentation.
Sample Source Patterns ¶
Teradata ¶
Query¶
Result¶
Snowflake Scripting¶
Query¶
Result¶
Known Issues ¶
No issues were found.
Related EWIs ¶
No related EWIs.
SYSTEM_DEFINED¶
Note
Some parts in the output code are omitted for clarity reasons.
Note
Non-relevant statement.
Warning
Notice that this statement isremoved from the migrationbecause it is a non-relevant syntax. It means that it is not required in Snowflake.
Description¶
Property in Teradata that can be after a CREATE statement in cases such as JOIN INDEX.
Sample Source Patterns¶
Notice that SYSTEM_DEFINED has been removed from the source code because it is a non-relevant syntax in Snowflake.
Teradata¶
Snowflake¶
Known Issues ¶
No issues were found.
Related EWIs¶
SSC-FDM-0007: Element with missing dependencies.
SSC-FDM-TD0025: Teradata Database Temporal Table is not supported in Snowflake.
SSC-FDM-0031: Dynamic Table required parameters set by default
WHILE¶
Translation reference to convert Teradata WHILE statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description ¶
Teradata’s WHILE statement is translated to Snowflake ScriptingWHILE syntax.
For more information, see the Teradata WHILE documentation.
Sample Source Patterns¶
Teradata¶
While¶
Result¶
Snowflake Scripting ¶
While¶
Result¶
Known Issues ¶
No issues were found.
Related EWIs ¶
No related EWIs.