Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E0003 type-mismatch

Type incompatibility in expression.

CodeNameCategoryDefault
E0003type-mismatchcorrectnesserror

What it reports

An expression combines values whose types the database won't implicitly convert: a comparison or arithmetic between incompatible types, an INSERT or UPDATE value that doesn't fit the column, CASE branches of different types, or a value that isn't one of an enum's labels.

String literals are treated like the database treats them: created_at > '2024-01-01' and id = '42' are fine, while id = 'abc' is reported.

Example

SELECT id FROM users WHERE id = 'abc';
error[E0003]: Type mismatch: cannot compare integer with text
  --> q.sql:1:28
    |
  1 | SELECT id FROM users WHERE id = 'abc';
    |                            ^^
    = help: Types are not implicitly compatible. Consider using explicit CAST.

Fixed:

SELECT id FROM users WHERE id = 42;

Notes

Enum values are checked too, with a suggestion for typos:

SELECT id FROM orders WHERE status = 'opne';
error[E0003]: Invalid value 'opne' for enum type 'order_status'
  --> q.sql:1:29
    |
  1 | SELECT id FROM orders WHERE status = 'opne';
    |                             ^^^^^^
    = help: Did you mean 'open'?

Date and timestamp literals that are certainly invalid (such as 'yesterday-ish' or '2024-02-30') are reported with a specific message rather than a cast hint:

SELECT id FROM orders WHERE ordered_on > '2024-02-30';
error[E0003]: Type mismatch: cannot compare date with text
  --> q.sql:1:42
    |
  1 | SELECT id FROM orders WHERE ordered_on > '2024-02-30';
    |                                          ^^^^^^^^^^^^
    = help: '2024-02-30' is not a valid date

MySQL and SQLite run most of these queries, converting the values at run time: there they are reported as the warning E0029, except assignments that the database rejects at run time: a string literal MySQL rejects when it is assigned (UPDATE users SET id = 'abc', an invalid ENUM label), and assignments to SQLite STRICT tables where SQLite rejects type mismatches.

See Dialects and SQL support for what sqlsift can infer. Anything it can't infer is never reported, and neither is arithmetic on a type whose operators sqlsift doesn't model: user-defined types, domains and extension types (MONEY, citext, ...), enums, arrays and JSONB.

Configuring

# sqlsift.toml
[rules]
type-mismatch = "warn"   # or "off"

Or for a single line: -- sqlsift:disable E0003. The examples use the schema on the Rules page.