RAISE
Description
Use the
RAISE level
statement to report messages and raise errors.
Variable declarations are fully supported by Snowflake.
Grammar Syntax
In Amazon Redshift, the RAISE
statement is used to generate messages in the console or throw custom exceptions. Redshift allows you to specify different levels to indicate the severity of the message. In Snowflake, this functionality can be emulated using a user-defined function (UDF) that makes a call to the console depending on the specified level.
Exception: When the level is "EXCEPTION", a custom exception is raised with a general message: "To view the EXCEPTION MESSAGE, you need to check the log." The exception code is
-20002
, which informs the user that the custom message can be found in the logs. This is due to limitations when sending custom exceptions in Snowflake.Warning: If the level is "WARNING",
SYSTEM$LOG_WARN
is used to print the warning message to Snowflake's log, which helps highlight potential issues without interrupting the flow of execution.Info: For any other level (such as "INFO"),
SYSTEM$LOG_INFO
is used to print the message to the console log, providing more detailed feedback about the system's state without causing critical disruptions.
This approach allows emulating Redshift's severity levels functionality, adapting them to Snowflake’s syntax and features, while maintaining flexibility and control over the messages and exceptions generated during execution.
Limitations
To view logs in Snowflake, it is necessary to have specific privileges, such as the
ACCOUNTADMIN
orSECURITYADMIN
roles.Logs in Snowflake are not available immediately and may have a slight delay before the information is visible.
Personalized error messages in exceptions are not displayed like in Redshift. To view custom messages, you must access the logs directly.
Sample Source Patterns
Input Code:
Output Code:
UDFs
Known Issues
There are no known issues.
Related EWIs.
There are no related EWIs.
Last updated