Andrea Casarin

Andrea Casarin

Published on: 11/13/2022, 1:51:38 PM - Reading time: 0 minute

Postgres, where and null

Some days ago I was working on a project which uses Postgres as DBMS. Postgres is great, but it has some significant differences if you are used to MySql. I learned one of them the hard way.

While doing a simple select query I was looking for tuples which were where x != 42 trying to extract all of them regardless of x being some number or null.

That didn't work as I expected. In Postgres if you select something via where x != 42 it will not extract tuples where x is null.

So, if you are doing something like I did make sure to explicitly include null as a where condition, for example where x != 42 or x is null.