{"record":{"id":"024d4c02e0963499","repo":"prestodb/presto","slug":"invalid-literal","errorCode":"INVALID_LITERAL","errorMessage":"'%s' is not a valid time literal","messagePattern":"'(.+?)' is not a valid time literal","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java","lineNumber":943,"sourceCode":"            try {\n                type = functionAndTypeResolver.getType(parseTypeSignature(node.getType()));\n            }\n            catch (IllegalArgumentException | UnknownTypeException e) {\n                throw new SemanticException(TYPE_MISMATCH, node, \"Unknown type: \" + node.getType());\n            }\n\n            return setExpressionType(node, type);\n        }\n\n        @Override\n        protected Type visitTimeLiteral(TimeLiteral node, StackableAstVisitorContext<Context> context)\n        {\n            boolean hasTimeZone;\n            try {\n                hasTimeZone = timeHasTimeZone(node.getValue());\n            }\n            catch (IllegalArgumentException e) {\n                throw new SemanticException(INVALID_LITERAL, node, \"'%s' is not a valid time literal\", node.getValue());\n            }\n            Type type = hasTimeZone ? TIME_WITH_TIME_ZONE : TIME;\n            return setExpressionType(node, type);\n        }\n\n        @Override\n        protected Type visitTimestampLiteral(TimestampLiteral node, StackableAstVisitorContext<Context> context)\n        {\n            try {\n                if (sqlFunctionProperties.isLegacyTimestamp()) {\n                    parseTimestampLiteral(sqlFunctionProperties.getTimeZoneKey(), node.getValue());\n                }\n                else {\n                    parseTimestampLiteral(node.getValue());\n                }\n            }\n            catch (Exception e) {\n                throw new SemanticException(INVALID_LITERAL, node, \"'%s' is not a valid timestamp literal\", node.getValue());","sourceCodeStart":925,"sourceCodeEnd":961,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java#L925-L961","documentation":"Presto raises this when a TIME literal's string value cannot be parsed to determine whether it carries a time zone. The literal keyword was accepted by the parser, but the value string is not a valid TIME format, so the analyzer cannot type the expression.","triggerScenarios":"Writing TIME 'not-a-time' or TIME '2020-01-01' (date only), or any malformed string inside TIME '...' in SQL.","commonSituations":"Hand-edited SQL with wrong literal format; copy-paste from other databases with different literal formats; missing quotes causing partial parse; locale-dependent formats like 12-hour times without AM/PM markers.","solutions":["Use the canonical format TIME 'HH:mm:ss[.SSS]' e.g. TIME '09:15:30.000'","Include the offset if a time-zone value is intended: TIME '09:15:30.000 UTC' or '+08:00'","Validate the literal string by running SELECT TIME '...' standalone before embedding in larger queries","If the source data is not a literal, cast a VARCHAR column instead: CAST(col AS TIME)"],"exampleFix":"// before\nSELECT TIME '9:15 AM';\n// after\nSELECT TIME '09:15:00.000';","handlingStrategy":"validation","validationCode":"// Validate TIME literal format before embedding:\nPattern TIME_LIT = Pattern.compile(\"^\\\\d{2}:\\\\d{2}(:\\\\d{2}(\\\\.\\\\d{1,9})?)?( \\\\S+)?$\");\nboolean ok = TIME_LIT.matcher(value).matches();","typeGuard":null,"tryCatchPattern":"try { run(sql); }\ncatch (PrestoException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"not a valid time literal\")) { /* reformat value */ }\n  else throw e;\n}","preventionTips":["Always emit TIME literals as HH:mm:ss[.fraction] (24-hour)","Append the zone only when intended (TIME WITH TIME ZONE)","Normalize 12-hour input to 24-hour before building SQL","Test literals standalone before embedding in large queries"],"tags":["presto","literal","time","parse-error"],"backgroundTag":"invalid-time-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"}