postgresql Postgres 中的不等于和空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36508815/
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
Not equal and null in Postgres
提问by faiwer
How I can filter SQL results with !=
in PostgreSQL SQL query? Example
如何!=
在 PostgreSQL SQL 查询中过滤 SQL 结果?例子
SELECT * FROM "A" WHERE "B" != 'C'
Working. But it's also filtered all record where "B" IS NULL
. When I changed query to:
在职的。但它也过滤了所有记录 where "B" IS NULL
。当我将查询更改为:
SELECT * FROM "A" WHERE "B" != 'C' OR "B" IS NULL
I'm got right result. O_o. Always, when I need using !=
I need also check OR "field" IS NULL
? Really?
我得到了正确的结果。哦哦。总是,当我需要使用时,!=
我还需要检查OR "field" IS NULL
? 真的吗?
It's uncomfortable in Sequelize: { B: { $or: [null, { $not: 'C' }] } }
, instead: { B: { $not: 'C' } }
:(
在 Sequelize 中很不舒服:{ B: { $or: [null, { $not: 'C' }] } }
,而是:{ B: { $not: 'C' } }
:(
回答by a_horse_with_no_name
You can use the "null safe" operator is distinct from
instead of <>
您可以使用“空安全”运算符is distinct from
而不是<>
SELECT *
FROM "A"
WHERE "B" is distinct from 'C'
http://www.postgresql.org/docs/current/static/functions-comparison.html
http://www.postgresql.org/docs/current/static/functions-comparison.html
You should also avoid quoted identifiers. They are much more trouble then they are worth it
您还应该避免引用标识符。他们的麻烦比他们值得