加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 检查Postgres复合字段是否为空/空

发布时间:2020-12-12 08:23:29 所属栏目:MsSql教程 来源:网络整理
导读:使用 postgres composite types,您可以基本构建一个将结构定义为另一个表的字段.我有一个类型为“person”的复合字段称为“收件人”.在我的具体情况下,此收件人字段通常为空.检查复合字段是否为空的正确方法是什么?我试过了: select * from bla where recip
使用 postgres composite types,您可以基本构建一个将结构定义为另一个表的字段.我有一个类型为“person”的复合字段称为“收件人”.在我的具体情况下,此收件人字段通常为空.检查复合字段是否为空的正确方法是什么?我试过了:
select * from bla where recipient is not null
select * from bla where recipient is null
select * from bla where recipient = null
select * from bla where recipient != null

在所有这些情况下,它不返回任何东西.那么如何正确地检查一个复合值是否为空?

UPDATE

经过一些阅读,看起来这是我的问题:

One may think that !(x IS NULL) = x IS NOT NULL is true in all cases. But there is an exception – composite types. When one field of a composite value is NULL and another field is NOT NULL,then result of both operators is false. IS NULL is true,only when all fields are NULL. IS NOT NULL is true,only when all fields are NOT NULL. For any case in between,then both operators return false.

我确实有一些字段为null,而其他的那些不是.我希望该字段被认为是非NULL,如果复合字段中的任何项不为null,则不是当它们都不为空时.除了检查每个领域,是否有任何办法?

解决方法

IS NULL和IS NOT NULL也适用于复杂类型,所以这两个应该是适当的:
select * from bla where recipient is not null
select * from bla where recipient is null

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读