Skip to content

Compile IN and NOT IN lists with non-literal items to close #2874 - #2905

Open
komal0000 wants to merge 3 commits into
AlaSQL:developfrom
komal0000:fix/in-list-non-literal-items
Open

komal0000 wants to merge 3 commits into
AlaSQL:developfrom
komal0000:fix/in-list-non-literal-items

Conversation

@komal0000

Copy link
Copy Markdown
Contributor

Fixes #2874

Problem

With the statement cache on (the default), a IN (-1, 5), a IN (1 + 2, 5) and a IN (b, 5) only matched 5, and NOT IN let the same rows through. With alasql.options.cache = false the results were right.

Cause

The cached path in src/50expression.js builds its Set from item.value of each list item. -1 is a unary minus, 1 + 2 an operator and b a column, so none of them has a value, and each became undefined in the Set.

Fix

The cached Set is now used only when every list item is a NumValue or StringValue. Any other item (including parameters, which were already excluded) goes through the existing per-query new Set([...]) path, which compiles each item. Lists of plain literals keep the cached Set.

Tests

New test/test2874.js: IN with a negative number, an expression and a column; NOT IN with a negative number and a column; plain literals still work.

  • Without the change in src/, 5 of the 6 tests fail.
  • With it: bun test ... ./test/test2874.js → 6 passed.
  • Full suite → 2450 passed, 10 failed. The same 10 (test 107-B Excel files and CLI tests) also fail on clean develop on my Windows machine, so they are environmental.

The fix follows the one described in the issue, so @mathiasrw is credited as co-author.

@mathiasrw mathiasrw modified the milestones: v4.x Focus, v5.0.0 Oct 27, 2026
@komal0000
komal0000 force-pushed the fix/in-list-non-literal-items branch from 5379bce to 628d77b Compare October 29, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants