is_distinct_from.rb

lib/sequel/extensions/is_distinct_from.rb
Last Update: 2022-08-02 16:36:07 -0700

The is_distinct_from extension adds the ability to use the SQL standard IS DISTINCT FROM operator, which is similar to the not equals operator, except that NULL values are considered equal. PostgreSQL, SQLite 3.39+, and H2 currently support this operator. On other databases, support is emulated.

First, you need to load the extension into the database:

DB.extension :is_distinct_from

Then you can use the Sequel.is_distinct_from to create the expression objects:

expr = Sequel.is_distinct_from(:column_a, :column_b)
# (column_a IS DISTINCT FROM column_b)

You can also use the is_distinct_from method on most Sequel expressions:

expr = Sequel[:column_a].is_distinct_from(:column_b)
# (column_a IS DISTINCT FROM column_b)

These expressions can be used in your datasets, or anywhere else that Sequel expressions are allowed:

DB[:table].where(expr)

Related module: Sequel::SQL::IsDistinctFrom