How I can filter SQL results with !=
in PostgreSQL SQL query? Example
SELECT * FROM "A" WHERE "B" != 'C'
Working. But it's also filtered all record where "B" IS NULL
. When I changed query to:
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?
It's uncomfortable in Sequelize: { B: { $or: [null, { $not: 'C' }] } }
, instead: { B: { $not: 'C' } }
:(
Note. <> is the standard SQL notation for “not equal”. !=
<> is the standard SQL operator meaning "not equal". Many databases, including postgresql, supports != as a synonym for <> . They're exactly the same in postgresql.
Example - With SELECT StatementSELECT * FROM employees WHERE first_number IS NULL; This PostgreSQL IS NULL example will return all records from the employees table where the first_name contains a NULL value.
Oracle reads empty strings as NULLs, while PostgreSQL treats them as empty. Concatenating NULL values with non-NULL characters results in that character in Oracle, but NULL in PostgreSQL. Oracle and PostgreSQL behave similarly in many cases, but one way they differ is in their treatment of NULLs and empty strings.
You can use the "null safe" operator is distinct from
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 trouble then they are worth it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With