PostgreSQL’s IS DISTINCT FROM.

Vasiliy Ermolovich
hyperoslo
Published in
1 min readJul 2, 2018

Sometimes you need to find records which field is not equal to given value or isNULL. And instead of writing something like:

User.where('email != ? OR email IS NULL', 'test@example.com')

you can use pretty handy PostgreSQL’s IS DISTINCT FROM comparison operator:

User.where('email IS DISTINCT FROM ?', 'test@example.com')

--

--