Skip to content

An expression inside an IN list never matches: WHERE c IN (7 * 2) or IN (1, b) (a regression) #2771

Open

Description

@mathiasrw

An IN list matches only plain literals. Any expression in the list never matches: a column (WHERE a IN (1, b), WHERE c0 IN (c0)), a sign (IN (+ 14), even a negative number: IN (-14)), arithmetic (IN (7 * 2)), a function (IN (ABS(-14))) or parentheses (IN ((14))). It is a regression: it worked from 0.3.0 to 4.1.11, failed in 4.2.0, worked again in 4.2.1 and fails since 4.2.2. Those releases brought "Performance optimizations" (#1822, 4.2.0) and "Support cache for WHERE (NOT) IN" (#1834, 4.2.2). Seen about 7,000 times in the sqllogictest run (test/random/aggregates/, for example WHERE col1 IN ( - ( col1 ), ..., col1, ... ) and WHERE + col1 NOT IN ( + 14 )), reproduced on develop (06211a0) and npm 4.20.1, compared with SQLite 3.43.2:

alasql('SELECT a FROM ? WHERE a IN (1, b)', [[{a: 1, b: 5}, {a: 5, b: 5}, {a: 7, b: 3}]]);
// 4.1.11: [{a: 1}, {a: 5}]   since 4.2.2: [{a: 1}]
List (c1 = 14 in the row) 4.1.11 4.2.2 to develop SQLite
c1 IN (14) match match match
c IN (-14) with c = -14 match no match match
c1 IN (+ 14), (- -14), (7 * 2), (13 + 1), (ABS(-14)), ((14)) match no match match
c1 IN ('14') no match match no match (INTEGER column)
Query (t holds c0, c1 = (1, 10), (2, 20), (3, 30)) AlaSQL SQLite
SELECT c0 FROM t WHERE c0 IN (c0) no rows 1, 2, 3
SELECT c0 FROM t WHERE c0 IN (c0, 99) no rows 1, 2, 3
SELECT c0 FROM t WHERE c0 IN (c1 / 10) no rows 1, 2, 3
SELECT a IN (b) AS v FROM ? with {a: 1, b: 1} false true

NOT IN gives the opposite: c1 NOT IN (+ 14) keeps the row.

Not breaking: the fix gives back the answer of 4.1.11 and before. The '14' row is the other way round: today's loose match of text and number has been there since 4.2.2, so changing it would be breaking. Related: #2753 (a constant IN list returns the answer of an earlier list with the same text).

Activity

  1. changed the title [-]A column inside an IN list is not read per row: WHERE a IN (1, b) matches only 1 (regression since 4.2.2)[/-] [+]A column inside an IN list is not read per row: WHERE a IN (1, b) matches only 1 (a regression)[/+] on Oct 21, 2026
  2. changed the title [-]A column inside an IN list is not read per row: WHERE a IN (1, b) matches only 1 (a regression)[/-] [+]An expression inside an IN list never matches: WHERE c IN (7 * 2) or IN (1, b) (a regression)[/+] on Oct 21, 2026
  3. mathiasrw commented on Oct 21, 2026

    @mathiasrw
    MemberAuthor

    A correction to the c1 IN ('14') row: it is not a loose match of text and number. It is the IN list cache of #2753. The answer depends on which list ran first in the process (npm 4.20.1, CREATE TABLE v (c1 INTEGER) holding 14):

    Order in one process c1 IN (14) c1 IN ('14')
    IN ('14') first, then IN (14) no match (wrong) no match
    IN (14) first, then IN ('14') match match

    Run alone, c1 IN ('14') never matches, and neither does c1 = '14'. So nobody can rely on the match, and no part of this issue is breaking. The cache fix belongs to #2753.

    SQLite 3.43.2 matches in both cases for an INTEGER column, because the column's affinity turns '14' into 14 (c1 = '14' matches too). For a column without a type it does not match.

  4. added this to the v4.x Focus milestone on Oct 21, 2026
  5. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

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

  6. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

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

  7. modified the milestones: v4.x Focus, v5.0.0 on Nov 15, 2026
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