Repository navigation
Description
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 * 3is evaluated to6, and a TEXT column then stores it as the text'6'.- An unquoted word is a column name:
SET name = activefails 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
docs: credit CastleSoft for #506, #525 and the #518-#524 engine stack
MPCoreDeveloper commentedon Nov 28, 2026
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:
CASE, comparisons all evaluate as SQLite does, which is what the “never less than SQLite” policy requires.SET status = active), so existing hand-written SQL that SQLite rejects keeps working — an extension the policy allows, not a regression.@p): this only affects hand-written SQL with unquoted values.Where
masteris todayThe engine already evaluates row-reading and function expressions in
UPDATE … SET(#518) and constant arithmetic when the literal reading fails —SET n = 2 * 3on anINTEGERalready yields6.INSERT … VALUESdoes not yet evaluate expressions. So today the behaviour is closest to Option 3, and your table (SET name = 2 * 3→'2 * 3', unquotedSET d = 2024-01-15,upper('abc')in a VALUES list) still diverges.What shipping Option 2 means
A follow-up PR will:
UPDATE SETandINSERT VALUESthat parses as an expression;CHANGELOGnote listing the inputs whose stored value changes (unquoted dates become arithmetic; constant arithmetic intoTEXTbecomes the evaluated value).If you want any exception kept — for example, unquoted dates staying dates in
DATETIMEcolumns — reply here and I'll fold it into the PR.Leaving this open until the Option 2 PR lands.
feat: evaluate unquoted expressions in UPDATE SET and INSERT VALUES (…
MPCoreDeveloper commentedon Nov 28, 2026
Option 2 is implemented on
master— commit5d006c11(feat: evaluate unquoted expressions in UPDATE SET and INSERT VALUES (option 2 of #525)).What landed:
UPDATE … SETandINSERT … VALUESnow evaluate any value that parses as an expression — constant arithmetic, a function of literals, a comparison — matching SQLite.INSERT … VALUES (…, 2 * 3, …)now stores6(inTEXTas'6'and inINTEGERas6), andupper('abc')stores'ABC'.SET status = active) keeps the lenient literal reading — the case where SQLite itself raises "no such column" — as you framed it.DATETIMEcolumn stays a date. SharpCoreDB is typed, so the column cannot hold the integer2008that SQLite's2024-01-15arithmetic would store. Everything else follows SQLite.ExecuteBatchSQLINSERT 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:
tests/SharpCoreDB.Tests/ValuesExpressionSqliteCompatTests.cs(20 cases across columnar, page-based and single-file storage).'2 * 3',INTEGERarithmetic threwInvalid value '2 * 3',upper('abc')was stored as its own text, the batch path returned0) and all 20 pass now.SharpCoreDB.CI.slnfbuilds with 0 errors.docs/CHANGELOG.mdlists the inputs whose stored value changes (unquoted dates become arithmetic everywhere except aDATETIMEcolumn; constant arithmetic intoTEXTbecomes 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.
test(#525): 511-case differential matrix; fix VALUES paren split and …
MPCoreDeveloper commentedon Nov 28, 2026
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:
ParseInsertValuesdid not track parenthesis depth, so a multi-argument call such assubstr('abcdef', 2, 3)in a VALUES tuple was split at its own commas. It is now one value, as in SQLite.ParseValueFastread a numeric boolean (6) as false whileParseValueread 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.MPCoreDeveloper commentedon Nov 28, 2026
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
DATETIMEcolumn stays a date — a typed column cannot hold the integer2008that SQLite's2024-01-15arithmetic would store.Your measured table, now:
UPDATE … SET n = 2 * 3(INTEGER)UPDATE … SET name = 2 * 3(TEXT)'6''6'(was'2 * 3')UPDATE … SET d = 2024-01-15(DATETIME)UPDATE … SET name = active'active'(lenient)INSERT … VALUES (…, 2 * 3, …)→ TEXT'6''6'INSERT … VALUES (…, 2 * 3, …)→ INTEGERINSERT … 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.master: 4886 tests / 0 failed / 6 skipped across all 17 test projects.ParseInsertValuesnow tracks parenthesis depth (sosubstr('abcdef', 2, 3)in a VALUES tuple is one value, as in SQLite), and the batch parser reads a numeric boolean the wayParseValuedoes (any non-zero number is true).5d006c11(implementation) anda4293fb2(matrix + the two fixes).This is on
masternow 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.