4

首先采取,kludge解决方案,哨兵方法(您的程序必须不允许输入哨兵值):

 select coalesce(a, -2147483648) = coalesce(b, -2147483648) as is_equal -- a little postgresism

假设您忘记阻止程序中的标记值,用户在 B 字段中输入了 -2147483648,而 A 为空。上面的代码报告 true,应该报告 false,不应该报告 true 或 null。

在可空字段上比较相等性的最简洁方法是什么?A == B 应该只报告真或假,无论字段是否可以为空。

4

2 回答 2

10

可能IS [NOT] DISTINCT FROM在这里会有所帮助。

于 2009-03-25T09:48:41.207 回答
0

运算符 <=> 在其他数据库引擎中执行您想要的操作;它不在postgres中吗?否则,a is null and b is null or (a is not null and b is not null and a == b)应该工作。这有效,因为FALSE AND NULLis FALSE

于 2009-03-25T09:24:51.263 回答