postgresql 如何匹配not null + not empty?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41938704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to match not null + not empty?
提问by rap-2-h
I have to do some queries on a messy database. Some columns are filled with either null
or empty string. I can do query like this:
我必须对凌乱的数据库进行一些查询。某些列填充为null
空字符串或空字符串。我可以做这样的查询:
select * from a where b is not null and b <> '';
But is there a shortcut for this case? (match every "not empty" values) Something like:
但是这种情况有捷径吗?(匹配每个“非空”值)类似:
select * from a where b is filled;
回答by Clodoaldo Neto
Just:
只是:
where b <> ''
will do what you want as null <> ''
is null and the row will not be returned
会做你想做的事情,因为它null <> ''
是空的,并且不会返回该行
回答by Steve Smith
select * from a where COALESCE(b, '') <> '';
select * from a where COALESCE(b, '') <> '';