Skip to content

NOT binds tighter than IN and BETWEEN: WHERE NOT x IN (32) finds no rows #2768

Closed

Description

@mathiasrw

NOT binds tighter than IN and BETWEEN, so NOT x IN (...) is read as (NOT x) IN (...). In SQL, NOT binds looser than the comparison operators, so it means NOT (x IN (...)). #386 fixed this for NOT a = b; IN and BETWEEN still have the old order. Seen in the sqllogictest run (test/random/expr/, for example CASE WHEN NOT 5 IN ( 43 + - 11 ) THEN ...), reproduced on develop (06211a0) and npm 4.20.1, compared with SQLite 3.43.2:

alasql('CREATE TABLE u (x)');
alasql('INSERT INTO u VALUES (5), (0)');
Query AlaSQL SQLite
SELECT x FROM u WHERE NOT x IN (32) no rows 5, 0
SELECT x FROM u WHERE NOT (x IN (32)) 5, 0 5, 0
SELECT x FROM u WHERE NOT x BETWEEN 1 AND 3 0 5, 0
SELECT NOT 5 IN (32) false 1
SELECT NOT 0 IN (1) false 1
SELECT NOT 5 BETWEEN 1 AND 3 false 1
SELECT NOT -48 NOT BETWEEN -53 AND 29 false 1
SELECT NOT 5 = 3, NOT 5 > 3, NOT 5 LIKE 6, NOT 5 IS NULL same as SQLite

Not breaking: the answer is wrong for every row, as it was for = before #386.

Activity

  1. mathiasrw commented on Oct 21, 2026

    @mathiasrw
    MemberAuthor

    The same with a parenthesised left operand, the most common form in test/random/aggregates/ (WHERE NOT ( col2 ) IN ( + 5 ), WHERE NOT ( - col2 ) BETWEEN - col1 AND 84). t holds c0 = 1, 2, 3; develop 06211a0, SQLite 3.43.2:

    Query AlaSQL SQLite
    SELECT c0 FROM t WHERE NOT (c0) IN (2) no rows 1, 3
    SELECT c0 FROM t WHERE NOT ( c0 ) BETWEEN 2 AND 3 no rows 1
    SELECT NOT (2) IN (5) false 1
    SELECT NOT (2) <= 1 true 1
  2. added this to the v4.x Focus milestone on Oct 21, 2026
  3. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I'd like to work on this one.

  4. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I've opened a PR for this: #3047

  5. added a commit that references this issue on Nov 17, 2026
    1d37743
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