{"id":"1af64189ad1bbc9c","repo":"drizzle-team/drizzle-orm","slug":"unexpected-param-value-chunk","errorCode":null,"errorMessage":"Unexpected param value: ${chunk}","messagePattern":"Unexpected param value: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/sql/sql.ts","lineNumber":322,"sourceCode":"\t\t{ escapeString }: BuildQueryConfig,\n\t): string {\n\t\tif (chunk === null) {\n\t\t\treturn 'null';\n\t\t}\n\t\tif (typeof chunk === 'number' || typeof chunk === 'boolean') {\n\t\t\treturn chunk.toString();\n\t\t}\n\t\tif (typeof chunk === 'string') {\n\t\t\treturn escapeString(chunk);\n\t\t}\n\t\tif (typeof chunk === 'object') {\n\t\t\tconst mappedValueAsString = chunk.toString();\n\t\t\tif (mappedValueAsString === '[object Object]') {\n\t\t\t\treturn escapeString(JSON.stringify(chunk));\n\t\t\t}\n\t\t\treturn escapeString(mappedValueAsString);\n\t\t}\n\t\tthrow new Error('Unexpected param value: ' + chunk);\n\t}\n\n\tgetSQL(): SQL {\n\t\treturn this;\n\t}\n\n\tas(alias: string): SQL.Aliased<T>;\n\t/**\n\t * @deprecated\n\t * Use ``sql<DataType>`query`.as(alias)`` instead.\n\t */\n\tas<TData>(): SQL<TData>;\n\t/**\n\t * @deprecated\n\t * Use ``sql<DataType>`query`.as(alias)`` instead.\n\t */\n\tas<TData>(alias: string): SQL.Aliased<TData>;\n\tas(alias?: string): SQL<T> | SQL.Aliased<T> {","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sql/sql.ts#L304-L340","documentation":"Thrown by SQL.mapInlineParam (sql.ts:322) when a value interpolated into a sql`` template cannot be inlined as a literal. The method handles null, number, boolean, string, and object; anything else (undefined, symbol, bigint, function) reaches the final throw. Inlining only happens for queries built with paramStyle 'inline' (e.g. sqlToQuery for dialects/databases that inline rather than bind placeholders).","triggerScenarios":"Interpolating undefined, a Symbol, a BigInt, or a function/class instance directly into sql`` and then building the query in inline-param mode (typical for SQLite/Prisma-style raw SQL or when using .toSQL() with invoke: 'inline'). Passing a custom column/SQL object whose toString() is not enough is fine, but a bare undefined is the classic trigger.","commonSituations":"A conditional that left a variable as undefined; a JSON field whose value was stripped to undefined; upgrading drizzle where the default param-inlining behaviour changed; passing a Date to an inline-built query on a path that does not special-case it.","solutions":["Ensure the value is one of null/number/boolean/string/object before interpolating; coerce or guard against undefined.","Use sql.placeholder() or bind parameters through .all()/.run() instead of inlining literals.","If you genuinely need inline SQL, stringify/serialize unsupported types (BigInt -> String) before interpolation."],"exampleFix":"// before\nconst q = sql`select * from t where id = ${maybeUndefined}`;\n// maybeUndefined === undefined -> 'Unexpected param value: undefined'\n\n// after\nconst id = maybeUndefined ?? null;\nconst q = sql`select * from t where id = ${id}`;","handlingStrategy":"validation","validationCode":"function inlineSafe(value) {\n  if (value === undefined) return null;\n  if (typeof value === 'bigint') return value.toString();\n  if (typeof value === 'symbol' || typeof value === 'function') {\n    throw new TypeError('Cannot inline ' + typeof value);\n  }\n  return value;\n}\n// then: sql`... ${inlineSafe(maybeUndef)}`","typeGuard":"const isInlineable = (v): boolean =>\n  v === null || ['number', 'boolean', 'string', 'object'].includes(typeof v);","tryCatchPattern":null,"preventionTips":["Prefer bound parameters (.run(params)) over inline interpolation.","Coerce undefined to null and bigint to string before interpolating into sql``.","Avoid interpolating functions/symbols; pass their string representation explicitly if needed."],"tags":["sql","params","inline","type-coercion"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}