Skip to content

WHERE a = null #368

Closed
Closed

Description

@mathiasrw

AlaSQL 0.2.0 has a bug related to selecting elements that ARE null

Short version

Selecting rows where a is null returns no rows

JSON.stringify(alasql('SELECT * from ? where a = null', [[{id:1,a:123},{id:2,a:null}]]))
"[]"

I expected it to return [{"id":2,"a":null}]

Long version

  • Selecting all works as expected
JSON.stringify(alasql('SELECT * from ? where 1', [[{id:1,a:123},{id:2,a:null}]]))
"[{"id":1,"a":123},{"id":2,"a":null}]"

  • Selecting rows where a is not null also works
JSON.stringify(alasql('SELECT * from ? where a != null', [[{id:1,a:123},{id:2,a:null}]]))
"[{"id":1,"a":123}]"

  • Selecting rows where a is null returns no rows
JSON.stringify(alasql('SELECT * from ? where a = null', [[{id:1,a:123},{id:2,a:null}]]))
"[]"

I expected it to return [{"id":2,"a":null}]


  • To find out if its because I missunderstood the = vs == part of AlaSQL i also tried
JSON.stringify(alasql('SELECT * from ? where a == null', [[{id:1,a:123},{id:2,a:null}]]))
"[]"

I also expected that to return [{"id":2,"a":null}]


  • But more strangely when I !== I get all rows
JSON.stringify(alasql('SELECT * from ? where a !== null', [[{id:1,a:123},{id:2,a:null}]]))
"[{"id":1,"a":123},{"id":2,"a":null}]"

Activity

  1. mathiasrw commented on Nov 18, 2015

    @mathiasrw
    MemberAuthor

    There is a syntax workaround:

    find a = null: WHERE NOT a

    find a = abc: WHERE a != null

    https://jsfiddle.net/7u1fxbq3/

  2. mathiasrw commented on Oct 21, 2026

    @mathiasrw
    MemberAuthor

    Thank you for reporting this. In SQL, a = null is never true, because NULL is not equal to anything, not even NULL. SQLite returns no rows for this query too, and AlaSQL follows SQLite, so we will keep this behaviour. To find the rows where a is null, use WHERE a IS NULL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions