THEN
当子句中使用 UDF 时,子句代码中会发生错误WHEN
,尽管函数返回 false。
-- a simple function for example
CREATE FUNCTION "is_one"
(
IN checkNum INTEGER
)
RETURNS is_one INTEGER
LANGUAGE SQLSCRIPT
AS
BEGIN
IF
:checkNum = 1
THEN
is_one := 1;
ELSE
is_one := 0;
END IF;
END;
SELECT "is_one"(1) FROM DUMMY; -- returns 1
SELECT "is_one"(0) FROM DUMMY; -- returns 0
-- error... [304]: division by zero undefined: cannot be divided by zero at function /()
SELECT
CASE
WHEN "is_one"(0) = 1 THEN 1/0
ELSE 0
END AS x
FROM DUMMY;
-- an error does not occur if the function is not used
-- returns 0
SELECT
CASE
WHEN 0 = 1 THEN 1/0
ELSE 0
END AS x
FROM DUMMY;
我希望输出为 0,但实际我得到一个错误。