E0003 type-mismatch
Type incompatibility in expression.
| Code | Name | Category | Default |
|---|---|---|---|
E0003 | type-mismatch | correctness | error |
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'?
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.