assert_true 函数

适用于:Databricks SQL check marked yes Databricks Runtime

如果 expr 不为 true,则返回错误。

语法

assert_true(condition [, message])

参数

  • condition:一个 BOOLEAN 表达式。
  • message:带有消息的可选 STRING 表达式。 默认为 '<condition>' is not true!

返回

如果未返回任何错误,则返回非类型化的 NULL

适用于:check marked yesDatabricks SQL check marked yes Databricks Runtime 14.2 及更高版本

返回的错误类是 USER_RAISED_EXCEPTIONSQLSTATEP0001

有关处理错误条件的详细信息,请参阅处理错误条件

示例

> SELECT assert_true(0 < 1);
 NULL

> SELECT assert_true(0 > 1);
 [USER_RAISED_EXCEPTION] '0 > 1' is not true! SQLSTATE: P0001

> SELECT assert_true(1 = 2, 'One is not two!');
 [USER_RAISED_EXCEPTION] One is not two! SQLSTATE: P0001