【问题标题】:How to match not null + not empty?如何匹配不为空+不为空?
【发布时间】:2017-06-15 18:36:38
【问题描述】:

我必须对杂乱无章的数据库进行一些查询。某些列填充有null 或空字符串。我可以这样查询:

select * from a where b is not null and b <> '';

但是这种情况有捷径吗? (匹配每个“非空”值)类似:

select * from a where b is filled;

【问题讨论】:

  • 不是重复的。另一个问题是null or empty,而这个问题是not null and not empty

标签: postgresql postgresql-9.5


【解决方案1】:

select * from a where COALESCE(b, '') &lt;&gt; '';

【讨论】:

    【解决方案2】:

    只是:

    where b <> ''
    

    null &lt;&gt; '' 为 null 时会做你想做的事,并且不会返回该行

    【讨论】:

      猜你喜欢
      • 2018-11-14
      • 1970-01-01
      • 2018-09-23
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      相关资源
      最近更新 更多