在大查询脚本中引发异常问题

Raise Exception issue in big query scripting

我想在大查询脚本中使用 RAISE 关键字将自定义消息打印为异常错误。 但是,下面的命令行在 raise 命令中抛出错误。但是,如果我删除 raise 命令,它工作正常。 你能帮我如何提出自定义错误消息吗? 另外,要了解更多关于 RAISE [USING MESSAGE = message];.

BEGIN
SELECT 1/0; -- attempts to divide by zero
RAISE USING message = "divisible with zero is not allowed.";
EXCEPTION WHEN ERROR THEN
SELECT FORMAT("Hey, you. When you executed %s at %s, it caused an error: %s. Please don't do that.", @@error.statement_text, @@error.formatted_stack_trace, @@error.message);
END;

The RAISE statement must only be used within an EXCEPTION clause. The RAISE statement will re-raise the exception that was caught, and preserve the original stack trace.

参考:https://cloud.google.com/bigquery/docs/reference/standard-sql/scripting#raise

所以如果你想用自定义消息引发异常,它应该是:

BEGIN
SELECT 1/0; -- attempts to divide by zero
EXCEPTION WHEN ERROR THEN
RAISE USING message = FORMAT("Hey, you. When you executed %s at %s, it caused an error: %s. Please don't do that.", @@error.statement_text, @@error.formatted_stack_trace, @@error.message);
END;