【发布时间】:2022-01-06 11:51:27
【问题描述】:
即使我在x != N 中检查了这种情况,以下代码也会引发can't calculate log of zero 错误
DO $$
DECLARE N integer;
BEGIN
select count(*) from mytable INTO N;
UPDATE
words
SET
measure =
CASE
WHEN x != N THEN 1 + log((N - x) / x)
ELSE 0
END;
END $$;
也试过了,同样的错误:
DO $$
DECLARE N integer;
BEGIN
select count(*) from mytable INTO N;
UPDATE words
SET measure = 1 + log((N-x)/x)
WHERE x <> N;
END $$;
【问题讨论】:
-
x 的数据类型是什么?如果这是一个整数,(N-x)/x 可能会变成 0。
-
@FrankHeikens 它确实是一个整数,谢谢
标签: sql postgresql