SnowConvert AI - Redshift - CONTINUE HANDLER¶
Description¶
Amazon Redshift, which uses PL/pgSQL for procedural logic, does not have a native DECLARE CONTINUE HANDLER statement in the same way as systems like DB2 or Teradata. In Redshift, exception handling is managed through EXCEPTION blocks within procedures.
However, when migrating code from database systems that use CONTINUE HANDLERs (such as DB2, Teradata, or other systems), SnowConvert AI transforms these constructs into equivalent Snowflake Scripting exception handling mechanisms.
A CONTINUE HANDLER allows execution to continue after an error occurs, performing specific actions when certain conditions are met. In Snowflake, this behavior is emulated using EXCEPTION blocks with appropriate error handling logic.
For more information about Redshift exception handling, see Exception Handling in PL/pgSQL.
Grammar Syntax¶
Redshift does not have native CONTINUE HANDLER syntax. However, when converting from other database systems, the source pattern typically looks like:
In Redshift, exception handling uses:
Sample Source Patterns¶
CONTINUE HANDLER Conversion to Snowflake¶
When migrating stored procedures from systems with CONTINUE HANDLER to Snowflake via Redshift, SnowConvert AI transforms them into Snowflake-compatible exception handling.
Input Code:¶
Source (DB2/Teradata Pattern)¶
Output Code:¶
Snowflake Scripting¶
CONTINUE HANDLER with SQLEXCEPTION¶
Input Code:¶
Source (DB2/Teradata Pattern)¶
Output Code:¶
Snowflake Scripting¶
CONTINUE HANDLER for NOT FOUND¶
Input Code:¶
Source (DB2/Teradata Pattern)¶
Output Code:¶
Snowflake Scripting¶
Known Issues¶
Limited CONTINUE HANDLER Emulation¶
The conversion from CONTINUE HANDLER to Snowflake exception handling has some limitations:
Execution Flow: True CONTINUE HANDLER behavior (continuing from the exact point of error) cannot be fully replicated in Snowflake.
Performance: Wrapping individual statements in exception blocks can impact performance.
Granularity: Statement-level exception handling may be required to properly emulate CONTINUE HANDLER behavior.
SQLSTATE Mapping¶
Not all SQLSTATE codes from source systems map directly to Snowflake exception types. SnowConvert AI performs best-effort mapping:
SQLSTATE '02000'(NO DATA) →NO_DATA_FOUNDSQLSTATE '23xxx'(Integrity Constraint Violation) →STATEMENT_ERRORGeneric SQLEXCEPTION →
OTHER
Known Issues¶
When migrating CONTINUE HANDLER patterns from other systems to Redshift and then to Snowflake, be aware that exception handling behavior may differ between systems. Thorough testing is recommended to ensure the converted code maintains the intended behavior.
SQLWARNING Handling¶
Source systems that use CONTINUE HANDLER for SQLWARNING conditions present special challenges:
Snowflake does not distinguish between warnings and errors in the same way
Warnings in source systems may be errors in Snowflake
Manual review of warning handling logic is recommended
Example¶
Source Pattern¶
Snowflake¶
Best Practices¶
When working with converted CONTINUE HANDLER code in Snowflake:
Test Thoroughly: Verify that error handling behavior matches the original system’s behavior.
Review Performance: Multiple exception blocks can impact performance; consider refactoring where appropriate.
Validate Error Conditions: Ensure that all error conditions from the source system are properly handled.
Use Transactions: Leverage Snowflake’s transaction support for data consistency.
Monitor Execution: Use Snowflake’s logging capabilities to track exception handling.