---
description: >-
  Translation reference to convert Teradata GET DIAGNOSTICS EXCEPTION statement
  to Snowflake Scripting
---

# GET DIAGNOSTICS EXCEPTION

{% hint style="info" %}
**Important Notice: Migration of Documentation Website**

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

[Official Snowflake Snowconvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs/translation-references/teradata/README)

For any immediate assistance or if you encounter any issues, please contact our support team at [snowconvert-support@snowflake.com](mailto:snowconvert-support@snowflake.com).

Thank you for your understanding.
{% endhint %}

{% hint style="info" %}
Some parts in the output code are omitted for clarity reasons.
{% endhint %}

## Description <a href="#description" id="description"></a>

> GET DIAGNOSTICS retrieves information about successful, exception, or completion conditions from the Diagnostics Area.

For more information regarding Teradata GET DIAGNOSTICS, check [here](https://docs.teradata.com/r/Teradata-VantageTM-SQL-Stored-Procedures-and-Embedded-SQL/March-2019/Condition-Handling/GET-DIAGNOSTICS).

```sql
GET DIAGNOSTICS
{
  [ EXCEPTION < condition_number >
    [ < parameter_name | variable_name > = < information_item > ]...
  ] 
  |
  [ < parameter_name | variable_name > = < information_item > ]...
}
```

## Sample Source Patterns <a href="#sample-source-patterns" id="sample-source-patterns"></a>

#### Teradata <a href="#example-code" id="example-code"></a>

{% tabs %}
{% tab title="Query" %}
{% code title="IN -> Teradata_01.sql" %}
```sql
CREATE PROCEDURE getDiagnosticsSample ()
BEGIN
    DECLARE V_MESSAGE, V_CODE VARCHAR(200);
    DECLARE V_Result INTEGER;
    
    SELECT c1 INTO V_Result FROM tab1;
    GET DIAGNOSTICS EXCEPTION 1
        V_MESSAGE = Message_Text,
        V_CODE = RETURNED_SQLSTATE;
END;
```
{% endcode %}
{% endtab %}
{% endtabs %}

#### Snowflake Scripting <a href="#expected-code" id="expected-code"></a>

{% tabs %}
{% tab title="Query" %}
{% code title="OUT -> Teradata_01.sql" %}
```sql
CREATE OR REPLACE PROCEDURE getDiagnosticsSample ()
RETURNS VARCHAR
LANGUAGE SQL
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "teradata",  "convertedOn": "06/18/2024" }}'
EXECUTE AS CALLER
AS
$$
    DECLARE
        V_MESSAGE VARCHAR(200);
        V_CODE VARCHAR(200);
        V_Result INTEGER;
    BEGIN
         
         
        SELECT
            c1 INTO
            :V_Result
        FROM
            tab1;
            V_MESSAGE := SQLERRM;
            V_CODE := SQLSTATE;
    END;
$$;
```
{% endcode %}
{% endtab %}
{% endtabs %}

## Known Issues

### CLASS\_ORIGIN, CONDITION\_NUMBER

{% hint style="danger" %}
The use of GET DIAGNOSTICS for CLASS\_ORIGIN, CONDITION\_NUMBER is not supported
{% endhint %}

#### Teradata <a href="#example-code" id="example-code"></a>

{% tabs %}
{% tab title="Query" %}
{% code title="IN -> Teradata_02.sql" %}
```sql
CREATE PROCEDURE getDiagnosticsSample ()
BEGIN
    DECLARE V_MESSAGE, V_CODE VARCHAR(200);
    DECLARE V_Result INTEGER;
    
    SELECT c1 INTO V_Result FROM tab1;
    GET DIAGNOSTICS EXCEPTION 5
        V_CLASS = CLASS_ORIGIN,
        V_COND = CONDITION_NUMBER;
END;
```
{% endcode %}
{% endtab %}
{% endtabs %}

#### Snowflake Scripting <a href="#expected-code" id="expected-code"></a>

{% tabs %}
{% tab title="Query" %}
{% code title="OUT -> Teradata_02.sql" %}
```sql
CREATE OR REPLACE PROCEDURE getDiagnosticsSample ()
RETURNS VARCHAR
LANGUAGE SQL
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "teradata",  "convertedOn": "06/18/2024" }}'
EXECUTE AS CALLER
AS
$$
    DECLARE
        V_MESSAGE VARCHAR(200);
        V_CODE VARCHAR(200);
        V_Result INTEGER;
    BEGIN
         
         
        SELECT
            c1 INTO
            :V_Result
        FROM
            tab1;
--            V_CLASS = CLASS_ORIGIN
                                  !!!RESOLVE EWI!!! /*** SSC-EWI-0058 - FUNCTIONALITY FOR 'GET DIAGNOSTICS DETAIL FOR CLASS_ORIGIN' IS NOT CURRENTLY SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
             
--            V_COND = CONDITION_NUMBER
                                     !!!RESOLVE EWI!!! /*** SSC-EWI-0058 - FUNCTIONALITY FOR 'GET DIAGNOSTICS DETAIL FOR CONDITION_NUMBER' IS NOT CURRENTLY SUPPORTED BY SNOWFLAKE SCRIPTING ***/!!!
             
    END;
$$;
```
{% endcode %}
{% endtab %}
{% endtabs %}

## Related EWIS

1. [SSC-EWI-0058](../../../general/technical-documentation/issues-and-troubleshooting/conversion-issues/general/ssc-ewi-0058): Functionality is not currently supported by Snowflake Scripting.
