Skip to content

Dialect test: compare alasql with SQLite expression by expression in CI (the reference engine for v5) #2593

Closed

Description

@mathiasrw

Proposal: a small test that runs a list of SQL expressions in alasql and in a real engine, compares the answers, and fails the build on any difference that is not written down as intended. The real engine is the reference for its dialect: the test asks it what the right answer is.

v5 decided that SQLite is the reference engine. Where v4 is inconsistent or wrong, the fix takes SQLite's answer. If SQLite does not have the function, PostgreSQL's answer is used. If neither has it, the answer comes from the engine the function comes from. This test is how that decision is kept honest.

How it would live in the repository

  • test/dialect/cases.sql: the expressions, one per line. Anyone can add a line.
  • A test that runs every line in alasql and in SQLite. bun:sqlite is already in the test runner, so no dependency is needed.
  • test/dialect/expected-differences: the lines where the alasql dialect is meant to differ, each with its reason (for example "1 / 2: JavaScript division"). This file is the documented list of deviations, kept honest by CI.
  • A new difference that is not in that file fails the build.
  • The same list, run with alasql/dialect/sqlite loaded, should have an almost empty differences file. The same goes for PGlite with alasql/dialect/postgres. That is how a dialect module is tested.

What it changes: a semantics question stops being a debate in a pull request. It becomes a line in a file, with an expected value.

The measurement behind the decision (2026-10-13)

89 expressions were run in alasql (develop at 4af758bb, v4.20.0), SQLite 3.43.2 (bun:sqlite) and PostgreSQL 18.6 (PGlite 0.5.9). They covered NULL handling, MIN/MAX, strings, numbers, casts, aggregates, grouping, WHERE and ORDER BY. null against undefined, and true against 1, were counted as the same answer.

Expressions
alasql gives SQLite's answer 56 of 89 (63%)
alasql gives PostgreSQL's answer 49 of 89 (55%)
both 43
SQLite only 13
PostgreSQL only 6
neither 27 (30%)

Where the two references disagree with each other and alasql sides with one:

Expression alasql SQLite PostgreSQL alasql is with
'abc' LIKE 'A%' true 1 false SQLite
"dq" 'dq' 'dq' error SQLite
1 || 2 '12' '12' error SQLite
'5' = 5 false 0 true SQLite
0.1 + 0.2 = 0.3 false 0 true SQLite
CAST(3.7 AS INT) 3 3 4 SQLite
CAST(-3.7 AS INT) -3 -3 -4 SQLite
CAST('' AS INT) 0 0 error SQLite
GREATEST(1, NULL), LEAST(1, NULL) NULL NULL 1 SQLite
ORDER BY n DESC, first row 5 5 NULL SQLite
ORDER BY s, first row NULL NULL '10' SQLite
ORDER BY s DESC, first row 'c' 'c' NULL SQLite
GREATEST(NULL, 1) 1 NULL 1 PostgreSQL
GREATEST(10, '9') 10 '9' 10 PostgreSQL
CONCAT('a', NULL, 'b') 'ab' error (added in 3.44) 'ab' PostgreSQL
'5' < 10 true 0 true PostgreSQL
10 < '9' false 1 false PostgreSQL
ORDER BY n, first row -3 NULL -3 PostgreSQL

The 27 where alasql agrees with neither:

Group Expression alasql SQLite PostgreSQL
Fault SUBSTR('abcdef', 0, 3) 'f' 'ab' 'ab'
Fault SUBSTR('abcdef', -1, 3) 'ef' 'f' 'a'
Fault SUBSTR('abcdef', -2) 'def' 'ef' 'abcdef'
Fault SUBSTR('abcdef', -7, 3) 'abc' 'ab' ''
Fault SUBSTR('abcdef', 2, -1) '' 'a' error
Fault SUBSTR(12345, 2, 2) throws '23' '23'
Fault LENGTH(123) undefined 3 3
Fault MAX(s) over strings undefined 'c' 'c'
Fault MIN(s) over strings undefined '10' '10'
Fault SUM(n) over no rows 0 NULL NULL
Fault CAST(NULL AS INT) 0 NULL NULL
Fault CAST('12abc' AS INT) 0 12 error
JavaScript 1 / 2 0.5 0 0
JavaScript 7 / 2 3.5 3 3
JavaScript -7 / 2 -3.5 -3 -3
JavaScript 1 / 0 Infinity NULL error
JavaScript ROUND(-2.5) -2 -3 -3
JavaScript '5' + 3 '53' 8 8
JavaScript 'abc' + 1 'abc1' 1 error
JavaScript UPPER('straße') 'STRASSE' 'STRAßE' 'STRAẞE'
Three-valued logic NOT (NULL = 1) true NULL NULL
Three-valued logic 2 IN (1, NULL) false NULL NULL
Three-valued logic 2 NOT IN (1, NULL) true NULL NULL
Three-valued logic NULL AND FALSE undefined 0 false
Three-valued logic WHERE NOT (n = 5), rows 4 3 3
Three-valued logic 'a' || NULL 'a' NULL NULL
Three-valued logic JOIN … ON a.g = b.g with NULL keys, rows 9 5 5

The groups:

Why SQLite and not PostgreSQL

For SQLite:

  • It is dynamically typed, like alasql. PostgreSQL answered 7 of the 89 with an error, and an untyped engine cannot take "error" as a reference value.
  • It computes in 64-bit floats, like JavaScript. PostgreSQL uses decimals, so 0.1 + 0.2 = 0.3 is true there.
  • It shares alasql's habits: double-quoted strings, [brackets] and backticks, LIKE not case sensitive.
  • The reference engine is free: bun:sqlite and node:sqlite are synchronous and need no dependency. PGlite works too, but it is a 25 MB dev dependency and asynchronous.
  • The sqllogictest corpus the project has run since 2016 is SQLite's (sqllogictest: what the results say (88%, NULL behaviour is the largest kind) and what to run next #2594).

Against SQLite:

  • Its function set is small: no GREATEST/LEAST, LEFT/RIGHT or LEN, and no date type.
  • Some of its answers nobody wants: every number sorts before every string, so 10 < '9' is true, and CAST('12abc' AS INT) is 12.

Starting point

The comparison was a 60-line script. Moving it into test/dialect/ is the first step. The expressions above are the first cases.sql.

Related: #2594 (sqllogictest), #2597, #2583, #2588, #2598.

Activity

  1. changed the title [-]Oracle test: compare alasql with SQLite expression by expression in CI (the reference engine for v5)[/-] [+]Dialect test: compare alasql with SQLite expression by expression in CI (the reference engine for v5)[/+] on Oct 20, 2026
  2. mathiasrw commented on Oct 20, 2026

    @mathiasrw
    MemberAuthor

    The dialect test is in #2729: test/dialect/ with cases.sql, the matrices for #2717, #2718, #2720 and #2722, and expected-differences. Running it in CI, the dialect modules and the review of the differences continue in #2730.

  3. added a commit that references this issue on Oct 21, 2026
    5222441
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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions