empty_array_ignore_nulls.rb

Path: lib/sequel/extensions/empty_array_ignore_nulls.rb
Last Update: Sat Aug 17 05:34:45 +0000 2013

This changes Sequel‘s literalization of IN/NOT IN with an empty array value to not return NULL even if one of the referenced columns is NULL:

  DB[:test].where(:name=>[])
  # SELECT * FROM test WHERE (1 = 0)
  DB[:test].exclude(:name=>[])
  # SELECT * FROM test WHERE (1 = 1)

The default Sequel behavior is to respect NULLs, so that when name is NULL, the expression returns NULL.

You can load this extension into specific datasets:

  ds = DB[:table]
  ds.extension(:empty_array_ignore_nulls)

Or you can load it into all of a database‘s datasets, which is probably the desired behavior if you are using this extension:

  DB.extension(:empty_array_ignore_nulls)

[Validate]