SnowConvert AI - Teradata - SQL to JavaScript (Procedures)¶
GET DIAGNOSTICS EXCEPTION¶
Translation reference to convert Teradata GET DIAGNOSTICS EXCEPTION statement to Snowflake Scripting
Description ¶
GET DIAGNOSTICS retrieves information about successful, exception, or completion conditions from the Diagnostics Area.
For more information, see the Teradata GET DIAGNOSTICS documentation.
Note
Some parts of the output code are omitted for clarity reasons.
Sample Source Patterns ¶
Teradata ¶
Query¶
Snowflake ¶
Javascript¶
Known Issues¶
Unsupported condition attributes statements
CLASS_ORIGIN
CONDITION_IDENTIFIER
CONDITION_NUMBER
MESSAGE_LENGTH
RETURNED_SQLSTATE
SUBCLASS_ORIGIN
If¶
The transformation for the IF statement is:
Teradata
Snowflake
Case¶
The transformation for the Case statement is:
Teradata
Snowflake
Cursor Declare, OPEN, FETCH and CLOSE¶
The transformation for cursor statements is:
Teradata
Cursor¶
Snowflake
JavaScript Cursor¶
While¶
The transformation for while statement is:
Teradata
While¶
Snowflake¶
While¶
Security¶
The transformation for security statements is:
Teradata |
Snowflake |
|---|---|
SQL SECURITY CREATOR |
EXECUTE AS OWNER |
SQL SECURITY INVOKER |
EXECUTE AS CALLER |
SQL SECURITY DEFINER |
EXECUTE AS OWNER |
FOR-CURSOR-FOR loop¶
The transformation for FOR-CURSOR-FOR loop is:
Teradata
For-Cursor-For-Loop¶
Snowflake
JavaScript For-Cursor-For-Loop¶
Note: The FOR loop present in the Teradata procedure is transformed to a FOR block in javascript that emulates its functionality.
Procedure parameters and variables referenced inside statements¶
The transformation for the procedure parameters and variables that are referenced inside the statements of the procedure is:
Teradata
Parameters and variables¶
Snowflake
JavaScript prameters and variables¶
Note: Whenever a procedure parameter or a variable declared inside the procedure is referenced inside a Teradata statement that has to be converted, this reference is escaped from the resulting text to preserve the original reference’s functionality.
Leave¶
In Javascript, it’s possible to use break with an additional parameter, thus emulating the behavior of a Teradata LEAVE jump.
Labels can also be emulated by using Javascript Labeled Statements.
The transformation for LEAVE statement is:
Teradata
Leave¶
Snowflake
JavaScript Leave¶
Getting Results from Procedures¶
Description of the translation¶
In Teradata, there are two ways to return data from a procedure. The first is through output parameters and the second through Dynamic Result Sets and Cursors. Both are shown in the following example. Each important point is explained below.
Example of returning data from a Stored Procedure¶
Teradata
Out parameter¶
Snowflake
JavaScript out parameter¶
In this converted SQL, there are several conversions that take place:
The
DYNAMIC RESULT SETS 2definition is converted to aDYNAMIC_RESULTSvariable.
When a cursor with an
WITH RETURNattribute is opened (and therefore a query is executed), its query ID is stored in the_OUTQUERIEScollection to be later returned. The query id is obtained by thegetQueryId()function provided in the JavaScript API for Snowflake stored procedures.Only the first k-query-IDs are stored in the collection, where k is the value of the
DYNAMIC_RESULTSvariable. This is done to emulate Teradata’s behavior, which only returns the first k-opened-cursors, even if more are opened in the stored procedure.The combination of
DECLARE CURSOR WITH RETURNwithPREPAREis translated to:
The output parameters are supported through the return statement of the procedure. An array is created containing the value of each output parameter and the
_OUTQUERIEScollection. ThePROCRESULTSfunction deals with the creation and filling of this array. See PROCRESULTS() helper for more information.
Example of getting data from a Stored Procedure¶
If the output parameters and the query IDs are returned from a procedure, a second one could call the first one to get these values, as shown below:
Teradata
Call procedure¶
Snowflake
JavaScript Call procedure¶
The value of the
P1argument fromProcedure1is returned and stored in theXvariable.The
_OUTQUERIESreturned fromProcedure1are stored in theresultsetvariable.
Note
This behavior also applies to the INOUT parameters.
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0022: One or more identifiers in this statement were considered parameters by default.
SSC-EWI-0023: Performance Review - A loop contains an insert, delete, or update statement.
SSC-EWI-0026: The variable may require a cast to date, time, or timestamp.
SSC-FDM-TD0001: This message is shown when SnowConvert AI finds a data type BLOB.