RESIGNAL statement
Applies to: Databricks Runtime 16.3 and later
Preview
This feature is in Public Preview.
Re-raises the condition handled by the condition handler.
This statement may only be used within a compound statement.
Syntax
RESIGNAL
Parameters
None
Examples
SQL
> CREATE TABLE log(eventtime TIMESTAMP, log STRING);
> BEGIN
DECLARE EXIT HANDLER FOR DIVIDE_BY_ZERO
BEGIN
DECLARE cond STRING;
DECLARE message STRING;
DECLARE state STRING;
DECLARE args MAP<STRING, STRING>;
DECLARE line BIGINT;
DECLARE argstr STRING;
DECLARE log STRING;
GET DIAGNOSTICS CONDITION 1
cond = CONDITION_IDENTIFIER,
message = MESSAGE_TEXT,
state = RETURNED_SQLSTATE,
args = MESSAGE_ARGUMENTS,
line = LINE_NUMBER;
SET argstr =
(SELECT aggregate(array_agg('Parm:' || key || ' Val: value '),
'', (acc, x)->(acc || ' ' || x))
FROM explode(args) AS args(key, val));
SET log = 'Condition: ' || cond ||
' Message: ' || message ||
' SQLSTATE: ' || state ||
' Args: ' || argstr ||
' Line: ' || line;
INSERT INTO log VALUES(current_timestamp(), log);
RESIGNAL;
END;
SELECT 10/0;
END;
[DIVIDE_BY_ZERO] Division by zero. Use try_divide to tolerate divisor being 0 and return NULL instead.
> SELECT * FROM log ORDER BY eventtime DESC LIMIT 1;
Condition: DIVIDE_BY_ZERO Message: Division by zero. Use try_divide to tolerate divisor being 0 and return NULL instead. SQLSTATE: 22012 Args: Line: 28
Related articles
- SQL Scripting
- CASE Statement
- Compound Statement
- SIGNAL Statement
- FOR Statement
- IF Statement
- ITERATE Statement
- REPEAT Statement
- SIGNAL Statement
- Error handling and error messages