Skip to content

IN and NOT IN ignore list items that are not plain literals: a IN (-1, 5) misses -1 #2874

Open

Description

@mathiasrw

With the statement cache on, which is the default, IN (...) and NOT IN (...) ignore every list item that is not a plain literal: a negative number, an expression, a column.

var data = [{a: -1, b: 0}, {a: 5, b: 0}, {a: 3, b: 3}];
alasql('SELECT a FROM ? WHERE a IN (-1, 5)', [data]);      // [{a: 5}]
alasql('SELECT a FROM ? WHERE a IN (1 + 2, 5)', [data]);   // [{a: 5}]
alasql('SELECT a FROM ? WHERE a IN (b, 5)', [data]);       // [{a: 5}]
alasql('SELECT a FROM ? WHERE a NOT IN (-1, 5)', [data]);  // [{a: -1}, {a: 3}]

alasql.options.cache = false;
alasql('SELECT a FROM ? WHERE a IN (-1, 5)', [data]);      // [{a: -1}, {a: 5}]
alasql('SELECT a FROM ? WHERE a IN (b, 5)', [data]);       // [{a: 5}, {a: 3}]

Expected: the results with the cache off.

The same in 4.20.0, so not new. The cached path builds its Set from item.value of each list item (src/expression/expression.js, the two allValues lines). -1 is a unary minus node, 1 + 2 an operator and b a column, so each has no value and becomes undefined. The fix: use the Set only when every item is a literal, and compile the list otherwise.

Breaking?

No. Wrong results made right.

Activity

  1. added a commit that references this issue on Oct 26, 2026
    c24d71c
  2. added this to the v4.x Focus milestone on Oct 27, 2026
  3. added a commit that references this issue on Oct 29, 2026
    6565a5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions