{"record":{"id":"0e3a06b2cc65b9c9","repo":"prestodb/presto","slug":"type-mismatch-0e3a06","errorCode":"TYPE_MISMATCH","errorMessage":"Unknown type: ","messagePattern":"Unknown type: ","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/planner/LiteralInterpreter.java","lineNumber":256,"sourceCode":"\n        @Override\n        protected Slice visitBinaryLiteral(BinaryLiteral node, ConnectorSession session)\n        {\n            return node.getValue();\n        }\n\n        @Override\n        protected Object visitEnumLiteral(EnumLiteral node, ConnectorSession context)\n        {\n            return node.getValue();\n        }\n\n        @Override\n        protected Object visitGenericLiteral(GenericLiteral node, ConnectorSession session)\n        {\n            Type type = metadata.getType(parseTypeSignature(node.getType()));\n            if (type == null) {\n                throw new SemanticException(TYPE_MISMATCH, node, \"Unknown type: \" + node.getType());\n            }\n\n            if (JSON.equals(type)) {\n                FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction(\"json_parse\", fromTypes(VARCHAR));\n                return functionInvoker.invoke(functionHandle, session.getSqlFunctionProperties(), ImmutableList.of(utf8Slice(node.getValue())));\n            }\n\n            try {\n                FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupCast(CAST, VARCHAR, type);\n                return functionInvoker.invoke(functionHandle, session.getSqlFunctionProperties(), ImmutableList.of(utf8Slice(node.getValue())));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SemanticException(TYPE_MISMATCH, node, \"No literal form for type %s\", type);\n            }\n        }\n\n        @Override\n        protected Long visitTimeLiteral(TimeLiteral node, ConnectorSession session)","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/planner/LiteralInterpreter.java#L238-L274","documentation":"visitGenericLiteral throws a SemanticException TYPE_MISMATCH when a generic literal like X'...' or MyType 'value' names a type unknown to the metadata registry. The type name must resolve before the literal can be cast.","triggerScenarios":"Evaluating GenericLiteral whose node.getType() (e.g. `FOO 'bar'`) is not a registered type.","commonSituations":"Typos in type names, using custom/connector types not installed, or dialect-specific syntax that Presto doesn't recognize.","solutions":["Fix the type name in the literal.","Use a supported type or explicit CAST instead of a generic literal.","Install the plugin providing the custom type."],"exampleFix":"// before\nSELECT MYTYPE 'abc';\n// after\nSELECT CAST('abc' AS VARCHAR);","handlingStrategy":"validation","validationCode":"if (metadata.getType(parseTypeSignature(literalType)) == null) { throw new SemanticException(TYPE_MISMATCH, node, \"Unknown type: \" + literalType); }","typeGuard":"boolean typeExists(Metadata metadata, String typeName) { return metadata.getType(parseTypeSignature(typeName)) != null; }","tryCatchPattern":"try { return LiteralInterpreter.evaluateGenericLiteral(node, session); } catch (SemanticException e) { if (e.getCode() == TYPE_MISMATCH) { /* fall back to CAST(string AS knownType) */ } else { throw e; } }","preventionTips":["Only use GenericLiteral with registered type names","Prefer explicit CAST over `Type 'value'` syntax","Install plugins for custom types before using them in literals"],"tags":["literal","type-system","semantic-error"],"backgroundTag":"unknown-type-cast","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}