{"record":{"id":"dddb236f2a0e841a","repo":"clockworklabs/SpacetimeDB","slug":"literal-values-for-type-are-not-supported","errorCode":null,"errorMessage":"Literal values for type {} are not supported","messagePattern":"Literal values for type (.+?) are not supported","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/expr/src/lib.rs","lineNumber":374,"sourceCode":"            value,\n            AlgebraicType::I256,\n            to_i256,\n            AlgebraicValue::I256,\n        ),\n        AlgebraicType::U256 => parse_int(\n            // Parse literal as U256\n            value,\n            AlgebraicType::U256,\n            to_u256,\n            AlgebraicValue::U256,\n        ),\n        AlgebraicType::String => Ok(AlgebraicValue::String(value.into())),\n        t if t.is_timestamp() => to_timestamp(),\n        t if t.is_bytes() => to_bytes(),\n        t if t.is_identity() => to_identity(),\n        t if t.is_connection_id() => to_connection_id(),\n        t if t.is_uuid() => to_uuid(),\n        t => bail!(\"Literal values for type {} are not supported\", fmt_algebraic_type(t)),\n    }\n}\n\n/// The source of a statement\npub enum StatementSource {\n    Subscription,\n    Query,\n}\n\n/// A statement context.\n///\n/// This is a wrapper around a statement, its source, and the original SQL text.\npub struct StatementCtx<'a> {\n    pub statement: Statement,\n    pub sql: &'a str,\n    pub source: StatementSource,\n}\n","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/expr/src/lib.rs#L356-L392","documentation":"When the SQL frontend converts a literal from query text into a typed AlgebraicValue, only scalar types are supported: all integer widths (I8..U256), floats, String, timestamp, bytes, identity, connection_id and uuid. The final match arm bails for anything else, i.e. complex algebraic types such as arrays, structs (product types), enums (sum types) and maps.","triggerScenarios":"Writing a SQL literal for a column whose schema type is a complex type, e.g. WHERE tags = 'x' where tags is Vec<String>, or an INSERT supplying a text literal for a struct/enum column.","commonSituations":"Filtering on array or enum columns via the SQL CLI or in subscriptions; hand-writing INSERT statements for tables with product/sum type columns; porting SQL intuitions from relational databases to SpacetimeDB's richer type system.","solutions":["Rewrite the predicate to a supported operation on the complex type (e.g. array containment operators) instead of literal equality.","Move the insert/filter logic into a module reducer where values are constructed as typed Rust values.","Filter on a scalar column (id, owner, status) and post-filter complex fields client-side."],"exampleFix":"-- before: literal against an array column\nSELECT * FROM posts WHERE tags = 'rust';\n\n-- after: use an array operator (or filter on a scalar column)\nSELECT * FROM posts WHERE 'rust' <@ tags;\n-- or do it in a reducer with typed Rust values","handlingStrategy":"validation","validationCode":"-- inspect column types before writing literal predicates:\nspacetime describe my-db\n-- avoid literals for array/struct/enum/map columns; only scalars\n-- (ints, floats, bool, string, timestamp, bytes, identity, uuid) parse from text","typeGuard":null,"tryCatchPattern":"// in Rust client code: build typed values in module reducers instead of SQL text\nmatch compile_sql_stmt(sql, tx, auth) {\n    Err(e) if e.to_string().contains(\"Literal values for type\") => {\n        // rewrite predicate to array operators or move logic into a reducer\n    }\n    other => other,\n}","preventionTips":["Check the table schema (spacetime describe) before hand-writing SQL literals.","Reserve SQL literals for scalar columns; handle complex types in typed reducer code.","Prefer parameters over inlined literal text where the client API supports them."],"tags":["sql","literals","type-system","query","type-mismatch"],"backgroundTag":"unsupported-literal-type","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}