错误处理函数接受字符串并在执行查询时返回该字符串。
1 - THROW_ERROR
返回用户定义的错误消息。
在多节点群集中,很少会导致错误消息的顺序不同。
行为类型
不可变语法
THROW_ERROR ( message )
参数
- message
- 要返回的 VARCHAR 字符串。
示例
遇到 CASE 语句时,返回错误消息:
=> CREATE TABLE pitcher_err (some_text varchar);
CREATE TABLE
=> COPY pitcher_err FROM STDIN;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> big foo value
>> bigger foo other value
>> bar another foo value
>> \.
=> SELECT (CASE WHEN true THEN THROW_ERROR('Failure!!!') ELSE some_text END) FROM pitcher_err;
ERROR 7137: USER GENERATED ERROR: Failure!!!
遇到使用 REGEXP_LIKE 的 CASE 语句时,返回错误消息:
=> SELECT (CASE WHEN REGEXP_LIKE(some_text, 'other') THEN THROW_ERROR('Failure at "' || some_text || '"') END) FROM pitcher_err;
ERROR 4566: USER GENERATED ERROR: Failure at "bar another foo value"