Skip to content

Question: how closely should unquoted UPDATE SET / INSERT VALUES expressions match SQLite? (options 1/2/3) #525

Done

Description

@CastleSoft

Question

How closely should unquoted values in UPDATE … SET and INSERT … VALUES match SQLite? Pick option 1, 2 or 3 below. Every option changes stored values for some unquoted input, so the choice also needs a CHANGELOG note.

Background

In SQLite, every value in an UPDATE SET list or an INSERT VALUES list is an expression:

  • 2 * 3 is evaluated to 6, and a TEXT column then stores it as the text '6'.
  • An unquoted word is a column name: SET name = active fails with "no such column".
  • Text has to be quoted: 'active'.

SharpCoreDB reads some unquoted values as literal text instead. The table below was measured on the current PR stack (#518–#524):

Statement SQLite SharpCoreDB today
UPDATE t SET n = 2 * 3 (INTEGER) 6 6
UPDATE t SET name = 2 * 3 (TEXT) '6' '2 * 3'
UPDATE t SET d = 2024-01-15 (DATETIME) 2008 (2024 − 1 − 15) 15 Jan 2024
UPDATE t SET name = active error: no such column 'active'
INSERT … VALUES (…, 2 * 3, …) into TEXT '6' '2 * 3'
INSERT … VALUES (…, 2 * 3, …) into INTEGER 6 error: "Invalid value '2 * 3'"
INSERT … VALUES (…, upper('abc'), …) 'ABC' "upper('abc')" (the text of the call)

Why UPDATE behaves this way

Before #518, every SET value was parsed as a literal of the column's type, and a TEXT column accepted the raw text.

#518 added expression support (SET n = n + 1, SET name = upper(name)). It treats a value as an expression only when it reads a column or calls a function. Constant arithmetic keeps the old literal reading, and is evaluated only when that reading fails. This was deliberate, to avoid silently changing what existing apps store:

Unquoted input Stored today Would become
SET d = 2024-01-15 a date 2008
SET sku = 10-4 '10-4' 6
SET status = active 'active' an error

Why INSERT is a separate gap

INSERT … VALUES never evaluates expressions:

  • a function call is stored as its own text;
  • arithmetic into a numeric column fails.

That is wider than constant arithmetic, and it is a SQLite incompatibility whichever option is chosen.

Callers that pass parameters (EF Core, linq2db, Dapper, ADO.NET with @p) are not affected by any of this. Only hand-written SQL with unquoted values is.

Options

Option 1 — Match SQLite fully

Every unquoted value in UPDATE SET and INSERT VALUES is evaluated as an expression, and an unknown bare word is rejected as an unknown column.

  • ✅ Exact SQLite behaviour; satisfies the "never less than SQLite" policy without exceptions.
  • ⚠️ Riskiest for existing hand-written SQL:
    • unquoted dates become arithmetic;
    • unquoted words start failing;
    • TEXT columns store the evaluated value.

Option 2 — Match SQLite wherever SQLite would succeed (recommended)

Anything that parses as an expression is evaluated, as in SQLite: arithmetic, function calls, CASE, comparisons.

The lenient literal reading stays only where SQLite would raise an error anyway: a bare word that names no column (SET status = active).

  • ✅ Every statement SQLite accepts gives SQLite's result. Unquoted dates and constant arithmetic match SQLite.
  • ✅ Statements SQLite rejects keep working as before (an extension, which the policy allows).
  • ⚠️ Unquoted dates and arithmetic-looking text change meaning, as in option 1.

Option 3 — Minimal change

UPDATE stays as it is. INSERT VALUES only gains evaluation of values that read a column or call a function, mirroring UPDATE today.

  • ✅ Lowest risk; existing stored values don't change.
  • ⚠️ The TEXT constant-arithmetic difference stays ('2 * 3' instead of '6'), and INSERT arithmetic into numeric columns keeps failing. This remains a SQLite incompatibility.

Recommendation

Option 2. It closes the incompatibility for everything SQLite accepts, doesn't touch parameterized callers, and keeps backward compatibility only where SQLite itself would fail.

What happens after a decision

  • The chosen option is implemented as a PR on top of the current stack.
  • Tests cover every row of the table above.
  • The CHANGELOG notes the inputs whose stored value changes.

Please reply with 1, 2 or 3, plus any exceptions you want kept (for example, unquoted dates in DATETIME columns).

Activity

  1. added
    question
    on Nov 17, 2026
  2. added a commit that references this issue on Nov 28, 2026
  3. MPCoreDeveloper commented on Nov 28, 2026

    @MPCoreDeveloper
    Owner

    Thanks @CastleSoft — this is exactly the question to pin down, and the measured table is what a decision like this needs. There was no answer on the thread yet, so here is the decision.

    Decision: Option 2

    Rationale:

    • It closes the SQLite incompatibility for every statement SQLite accepts — unquoted dates, constant arithmetic, function calls, CASE, comparisons all evaluate as SQLite does, which is what the “never less than SQLite” policy requires.
    • The lenient literal reading survives only where SQLite itself would error (a bare word that names no column, e.g. SET status = active), so existing hand-written SQL that SQLite rejects keeps working — an extension the policy allows, not a regression.
    • Parameterised callers are untouched (EF Core, linq2db, Dapper, ADO.NET @p): this only affects hand-written SQL with unquoted values.

    Where master is today

    The engine already evaluates row-reading and function expressions in UPDATE … SET (#518) and constant arithmetic when the literal reading fails — SET n = 2 * 3 on an INTEGER already yields 6. INSERT … VALUES does not yet evaluate expressions. So today the behaviour is closest to Option 3, and your table (SET name = 2 * 3 → '2 * 3', unquoted SET d = 2024-01-15, upper('abc') in a VALUES list) still diverges.

    What shipping Option 2 means

    A follow-up PR will:

    1. evaluate every value in UPDATE SET and INSERT VALUES that parses as an expression;
    2. reject a bare word that names no column, exactly as SQLite does;
    3. use your table above as the test matrix;
    4. add a CHANGELOG note listing the inputs whose stored value changes (unquoted dates become arithmetic; constant arithmetic into TEXT becomes the evaluated value).

    If you want any exception kept — for example, unquoted dates staying dates in DATETIME columns — reply here and I'll fold it into the PR.

    Leaving this open until the Option 2 PR lands.

  4. MPCoreDeveloper commented on Nov 28, 2026

    @MPCoreDeveloper
    Owner

    Option 2 is implemented on master — commit 5d006c11 (feat: evaluate unquoted expressions in UPDATE SET and INSERT VALUES (option 2 of #525)).

    What landed:

    • UPDATE … SET and INSERT … VALUES now evaluate any value that parses as an expression — constant arithmetic, a function of literals, a comparison — matching SQLite. INSERT … VALUES (…, 2 * 3, …) now stores 6 (in TEXT as '6' and in INTEGER as 6), and upper('abc') stores 'ABC'.
    • A bare word that names no column (SET status = active) keeps the lenient literal reading — the case where SQLite itself raises "no such column" — as you framed it.
    • One deliberate exception, which you offered in the issue: an unquoted date in a DATETIME column stays a date. SharpCoreDB is typed, so the column cannot hold the integer 2008 that SQLite's 2024-01-15 arithmetic would store. Everything else follows SQLite.
    • The ExecuteBatchSQL INSERT fast path reads through a second parser (PreparedInsertStatement.ParseValuesToArray); it now follows the same rule, so a batched insert and a plain one agree.

    Verification:

    • Your table is the test matrix: tests/SharpCoreDB.Tests/ValuesExpressionSqliteCompatTests.cs (20 cases across columnar, page-based and single-file storage).
    • Proved red→green: 10 of the 20 cases failed on the previous engine (TEXT constant arithmetic stored '2 * 3', INTEGER arithmetic threw Invalid value '2 * 3', upper('abc') was stored as its own text, the batch path returned 0) and all 20 pass now.
    • No regressions: core 2469 / 0, linq2DB 96 / 0, EF Core 116 / 0, VectorSearch 255 / 0; SharpCoreDB.CI.slnf builds with 0 errors.
    • docs/CHANGELOG.md lists the inputs whose stored value changes (unquoted dates become arithmetic everywhere except a DATETIME column; constant arithmetic into TEXT becomes the evaluated value).

    I'll close this once the release that carries it is published. Thanks again — your measured table made this a precise, testable change rather than a guess.

  5. added a commit that references this issue on Nov 28, 2026
  6. MPCoreDeveloper commented on Nov 28, 2026

    @MPCoreDeveloper
    Owner

    Follow-up on coverage: the option-2 contract now has a 511-case differential matrix — tests/SharpCoreDB.Tests/ValuesExpressionMatrixTests.cs. Every unquoted expression is asserted to store exactly what its equivalent literal stores, across integer/bigint/real/decimal/text/boolean columns × columnar/page-based/single-file storage × INSERT/UPDATE/batch.

    The matrix exposed and fixed two parse inconsistencies along the way:

    • ParseInsertValues did not track parenthesis depth, so a multi-argument call such as substr('abcdef', 2, 3) in a VALUES tuple was split at its own commas. It is now one value, as in SQLite.
    • The batch ParseValueFast read a numeric boolean (6) as false while ParseValue read it as true; both now treat any non-zero number as true, so the batch and single-statement INSERT paths agree.

    Full run before the next release: 4886 tests / 0 failed / 6 skipped across all 17 test projects. Commit a4293fb2.

  7. MPCoreDeveloper commented on Nov 28, 2026

    @MPCoreDeveloper
    Owner

    Closed as resolved — option 2 is chosen, implemented and verified.

    The decision: option 2 (match SQLite wherever SQLite would succeed, and keep the lenient literal reading only where SQLite itself raises "no such column"), with the one exception offered in the issue: an unquoted date in a DATETIME column stays a date — a typed column cannot hold the integer 2008 that SQLite's 2024-01-15 arithmetic would store.

    Your measured table, now:

    Statement SQLite SharpCoreDB
    UPDATE … SET n = 2 * 3 (INTEGER) 6 6
    UPDATE … SET name = 2 * 3 (TEXT) '6' '6' (was '2 * 3')
    UPDATE … SET d = 2024-01-15 (DATETIME) 2008 15 Jan 2024 (kept exception)
    UPDATE … SET name = active error 'active' (lenient)
    INSERT … VALUES (…, 2 * 3, …) → TEXT '6' '6'
    INSERT … VALUES (…, 2 * 3, …) → INTEGER 6 6 (was an error)
    INSERT … VALUES (…, upper('abc'), …) 'ABC' 'ABC'

    Evidence

    • ValuesExpressionSqliteCompatTests (20 cases; 10 failed before) and a 511-case differential matrix (ValuesExpressionMatrixTests) that asserts every expression stores exactly what its equivalent literal stores — across integer/bigint/real/decimal/text/boolean columns × columnar/page-based/single-file storage × INSERT/UPDATE/batch.
    • Full run on master: 4886 tests / 0 failed / 6 skipped across all 17 test projects.
    • The matrix exposed and fixed two further parse defects: ParseInsertValues now tracks parenthesis depth (so substr('abcdef', 2, 3) in a VALUES tuple is one value, as in SQLite), and the batch parser reads a numeric boolean the way ParseValue does (any non-zero number is true).
    • Commits: 5d006c11 (implementation) and a4293fb2 (matrix + the two fixes).

    This is on master now and will be included in the next published package (the current published version, 2.1.4, predates it).

    Thanks @CastleSoft — the measured table made this a precise, testable change rather than a guess. You're credited in CONTRIBUTORS.md.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions