什么时候“x IS NOT NULL”与“NOT(x IS NULL)”不同

发布于 2024-09-01 15:41:11 字数 475 浏览 5 评论 0原文

x 是什么

表达式x IS NOT NULL is不等于NOT(x IS NULL),如2VL中的情况

(引用自 这个答案,引用了Fabian Pascal 数据库管理中的实际问题 - 思考实践者的参考 - 接近答案的结尾)

我的猜测是当x IS NULL NULL,但我无法猜测什么时候会发生(即我没有检查 SQL 标准)。 这个猜测是不正确的。

For what x is

The expression x IS NOT NULL is not equal to NOT(x IS NULL), as is the case in 2VL

(quote from this answer, which is quoting Fabian Pascal Practical Issues in Database Management - A Reference for the Thinking Practitioner -- near the end of that answer)

My guess is when x IS NULL is NULL, but I cannot guess when that would be (i.e. I haven't checked the SQL standard). This guess was incorrect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

归途 2024-09-08 15:41:11

据我所知,Fabian Pascal 并不是指与 Null 相比的标量值,而是指很少实现的 ROW 类型。在标准中,想法是您可以使用 IS NULL 比较表(行)来确定是否所有值都设置为 NULL 值。因此,X IS NULL 表示所有值都设置为 NULL 值,X IS NOT NULL 表示没有值设置为 NULL 值,NOT ( X IS NULL) 意味着并非所有值都设置为 NULL 值,或者换句话说,至少存在一个未设置为 NULL 的值。诚然,我在这里轻轻地踩在巨人的肩膀上,但这就是我解释他的声明的方式。

From what I've read, Fabian Pascal is not referring to a scalar value in comparison to Null but the rarely implemented ROW type. In the standard, the idea was that you could compare a table (of rows) using IS NULL to determine if all values were set to the NULL value. Thus, X IS NULL would imply all values were set to the NULL value, X IS NOT NULL would mean no values were set to the NULL value and NOT (X IS NULL) would mean that not all values were set to the NULL value or, said another way, there existed at least one value not set to NULL. Granted, I'm treading lightly on the shoulders of giants here, but that's how I interpret his statement.

随心而道 2024-09-08 15:41:11

x IS NULL 永远不会是 NULL,因此它们对于所有 x 都是相同的

真值表啊嘿:

+--------+-------------+---------+--------------+
|   x    |x IS NOT NULL|x IS NULL|NOT(x IS NULL)|
+--------+-------------+---------+--------------+
|NULL    |    FALSE    |  TRUE   |    FALSE     |
|NOT NULL|    TRUE     |  FALSE  |    TRUE      |
+--------+-------------+---------+--------------+

请注意,第二列和第四列对于所有 x 都是相同的x 的潜在值(NULLNOT NULL

x IS NULL will never be NULL so they are the same for all x

Truth table ahoy:

+--------+-------------+---------+--------------+
|   x    |x IS NOT NULL|x IS NULL|NOT(x IS NULL)|
+--------+-------------+---------+--------------+
|NULL    |    FALSE    |  TRUE   |    FALSE     |
|NOT NULL|    TRUE     |  FALSE  |    TRUE      |
+--------+-------------+---------+--------------+

Note that columns two and four are identical for all potential values of x (either NULL or NOT NULL)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文