零安全等于比较

发布于 2025-02-12 10:29:19 字数 578 浏览 2 评论 0 原文

SQLITE 3.27:

有没有办法编写一种表达式,其中将 null null 进行比较?

例如:

with data (a,b) as (
values
(1,1),
(1,null),
(null,null)
)

select
  *
from
  data
where
  a = b

但是结果将是:

     a       b
------  ------
     1       1
(null)  (null)

     a       b
------  ------
     1       1

SQLite 3.27:

Is there a way to write an expression where comparing a null to a null would evaluate to true?

For example:

with data (a,b) as (
values
(1,1),
(1,null),
(null,null)
)

select
  *
from
  data
where
  a = b

But the result would be:

     a       b
------  ------
     1       1
(null)  (null)

Instead of:

     a       b
------  ------
     1       1

db<>fiddle

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

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

发布评论

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

评论(1

流心雨 2025-02-19 10:29:19

似乎答案是

使用代替 =

with data (a,b) as (
values
(1,1),
(1,null),
(null,null)
)

select
  *
from
  data
where
  a is b

结果:

     a       b
------  ------
     1       1
(null)  (null)

db&lt;&gt; fiddle


相关:

我没有较新版本的sqlite版本要测试。但是是语法在较新版本中不起作用。也许只有语法在sqlite的较新版本中起作用。

It looks like the answer is yes.

Use IS instead of =:

with data (a,b) as (
values
(1,1),
(1,null),
(null,null)
)

select
  *
from
  data
where
  a is b

Result:

     a       b
------  ------
     1       1
(null)  (null)

db<>fiddle


Related:

I don't have a newer version of SQLite to test in. But it's possible the is syntax doesn't work in newer versions. Maybe only the IS NOT DISTINCT FROM syntax works in newer versions of SQLite.

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