{"record":{"id":"eeb79c18c5886d3c","repo":"prestodb/presto","slug":"invalid-literal-eeb79c","errorCode":"INVALID_LITERAL","errorMessage":"Invalid formatted generic ${type} literal: ${node}","messagePattern":"Invalid formatted generic (.+?) literal: (.+?)","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/relational/SqlToRowExpressionTranslator.java","lineNumber":461,"sourceCode":"                throw new PrestoException(NOT_SUPPORTED, \"Unsupported type: \" + node.getType());\n            }\n\n            try {\n                if (TINYINT.equals(type)) {\n                    return constant((long) Byte.parseByte(node.getValue()), TINYINT);\n                }\n                else if (SMALLINT.equals(type)) {\n                    return constant((long) Short.parseShort(node.getValue()), SMALLINT);\n                }\n                else if (INTEGER.equals(type)) {\n                    return constant((long) Integer.parseInt(node.getValue()), INTEGER);\n                }\n                else if (BIGINT.equals(type)) {\n                    return constant(Long.parseLong(node.getValue()), BIGINT);\n                }\n            }\n            catch (NumberFormatException e) {\n                throw new SemanticException(SemanticErrorCode.INVALID_LITERAL, node, format(\"Invalid formatted generic %s literal: %s\", type, node));\n            }\n\n            if (JSON.equals(type)) {\n                return call(\n                        getSourceLocation(node),\n                        \"json_parse\",\n                        functionAndTypeResolver.lookupFunction(\"json_parse\", fromTypes(VARCHAR)),\n                        getType(node),\n                        constant(utf8Slice(node.getValue()), VARCHAR));\n            }\n\n            return call(\n                    getSourceLocation(node),\n                    CAST.name(),\n                    functionAndTypeResolver.lookupCast(\"CAST\", VARCHAR, getType(node)),\n                    getType(node),\n                    constant(utf8Slice(node.getValue()), VARCHAR));\n        }","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/relational/SqlToRowExpressionTranslator.java#L443-L479","documentation":"After visitGenericLiteral resolves the type (e.g. BIGINT), parsing the literal's value string with the type's parser throws NumberFormatException; the translator rethrows as SemanticException INVALID_LITERAL because the value does not match the declared type's format.","triggerScenarios":"A typed literal whose value cannot be parsed by the type, e.g. `BIGINT '12abc'` or `TINYINT '9999'` (out of byte range), during expression translation.","commonSituations":"Hand-written literals with stray characters; query builders interpolating unvalidated strings into typed literals; locale/precision mismatches when generating SQL.","solutions":["Correct the literal value so it parses for the declared type (e.g. `BIGINT '123'`).","Remove characters like underscores, units, or whitespace from the literal.","Use CAST('123' AS BIGINT) instead of a typed literal to get a clearer cast error path.","Validate/normalize values in the code that generates the SQL."],"exampleFix":"// before\nSELECT BIGINT '12,345'\n// after\nSELECT BIGINT '12345'","handlingStrategy":"validation","validationCode":"// Validate literal value against the declared type before generating SQL\nstatic String typedLiteral(String type, String value) {\n    switch (type.toLowerCase()) {\n        case \"bigint\": Long.parseLong(value); break;\n        case \"tinyint\": Byte.parseByte(value); break;\n        default: throw new IllegalArgumentException(\"unsupported\");\n    }\n    return type + \" '\" + value + \"'\";\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Parse values with the matching Java primitive parser before emitting typed literals","Strip formatting characters (commas, spaces) from numeric literals","Use CAST for user-supplied strings so failures surface as cast errors","Add unit tests for SQL generation with edge-case values"],"tags":["sql","literal","invalid-literal","semantic-error"],"backgroundTag":"invalid-literal","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}