Not equal and null in Postgres

How can I filter SQL results with != In a PostgreSQL SQL query? Example

 SELECT * FROM "A" WHERE "B" != 'C' 

Working. But he also filtered out the whole record, where "B" IS NULL . When I changed the request to:

 SELECT * FROM "A" WHERE "B" != 'C' OR "B" IS NULL 

I have the correct result. O_o. Whenever I need to use != , Do I also need to check OR "field" IS NULL ? Really?

This is inconvenient in Sequelize: { B: { $or: [null, { $not: 'C' }] } } , instead: { B: { $not: 'C' } } : (

+5
source share
1 answer

You can use the "null safe" is distinct from operator instead of <>

 SELECT * FROM "A" WHERE "B" is distinct from 'C' 

http://www.postgresql.org/docs/current/static/functions-comparison.html


You should also avoid quoted identifiers. They are much more problems than they are worth it.

+13
source

Source: https://habr.com/ru/post/1246738/