【问题标题】:Raise Exception issue in big query scripting在大查询脚本中引发异常问题
【发布时间】:2021-07-08 08:41:02
【问题描述】:

我想在大查询脚本中使用 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;

【问题讨论】:

    标签: exception stored-procedures google-bigquery bigquery-udf


    【解决方案1】:

    RAISE 语句只能在 EXCEPTION 子句中使用。 RAISE 语句将重新引发捕获的异常,并保留原始堆栈跟踪。

    参考: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;
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      相关资源
      最近更新 更多