ERROR HANDLING

Translation reference for the conversion of BTEQ Error Handling to Snowflake Scripting equivalent

The BTEQ error handling capabilities are based on the Teradata Database error codes. These are the standard error codes and messages produced in response to user-specified Teradata SQL statements. A BTEQ user cannot change, modify or delete these messages.

For more information regarding BTEQ Error Handling, check here.

Sample Source Patterns

Basic BTEQ Error Handling Example

The error conditions content is relocated in different statements in case ERRORCODE is different to zero, otherwise it can be located as the original code. First, the query above the if statement is relocated within a BEGIN - END block, where in case of an exception it will be caught in the EXCEPTION block. Second of all, the ERRORCODE variable will be changed to the variable declared indicating their SQLCODE with an EWI indicating that the exact number of the SQLCODE is not the same as the ERRORCODE in BTEQ.

IN -> Teradata_01.bteq
-- Additional Params: -q SnowScript
SELECT * FROM table1;
 
.IF ERRORCODE<>0 THEN .EXIT 1

.QUIT 0
OUT -> Teradata_01.sql
EXECUTE IMMEDIATE
$$
  DECLARE
    STATUS_OBJECT OBJECT := OBJECT_CONSTRUCT('SQLCODE', 0);
  BEGIN
    BEGIN
      -- Additional Params: -q SnowScript
      SELECT
        *
      FROM
        table1;
      STATUS_OBJECT := OBJECT_CONSTRUCT('SQLROWCOUNT', SQLROWCOUNT);
    EXCEPTION
      WHEN OTHER THEN
        STATUS_OBJECT := OBJECT_CONSTRUCT('SQLCODE', SQLCODE, 'SQLERRM', SQLERRM, 'SQLSTATE', SQLSTATE);
    END;
    IF (STATUS_OBJECT['SQLCODE'] /*** SSC-FDM-TD0013 - THE SNOWFLAKE ERROR CODE MISMATCH THE ORIGINAL TERADATA ERROR CODE ***/ != 0) THEN
      RETURN 1;
    END IF;
    RETURN 0;
  END
$$

Known Issues

No issues were found.

  1. SSC-FDM-TD0013: The Snowflake error code mismatch the original Teradata error code.

Last updated