{"record":{"id":"295e8893ab28a92c","repo":"prestodb/presto","slug":"generic-user-error-295e88","errorCode":"GENERIC_USER_ERROR","errorMessage":"'%s' is not a valid timestamp literal","messagePattern":"'(.+?)' is not a valid timestamp literal","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/planner/LiteralInterpreter.java","lineNumber":159,"sourceCode":"        }\n        if (type instanceof DateType) {\n            return new SqlDate(((Long) node.getValue()).intValue());\n        }\n        if (type instanceof TimeType) {\n            if (properties.isLegacyTimestamp()) {\n                return new SqlTime((long) node.getValue(), properties.getTimeZoneKey());\n            }\n            return new SqlTime((long) node.getValue());\n        }\n        if (type instanceof TimestampType) {\n            try {\n                if (properties.isLegacyTimestamp()) {\n                    return new SqlTimestamp((long) node.getValue(), properties.getTimeZoneKey(), MILLISECONDS);\n                }\n                return new SqlTimestamp((long) node.getValue(), MILLISECONDS);\n            }\n            catch (RuntimeException e) {\n                throw new PrestoException(GENERIC_USER_ERROR, format(\"'%s' is not a valid timestamp literal\", (String) node.getValue()));\n            }\n        }\n        if (type instanceof TimestampWithTimeZoneType) {\n            return new SqlTimestampWithTimeZone((long) node.getValue());\n        }\n        if (type instanceof IntervalDayTimeType) {\n            return new SqlIntervalDayTime((long) node.getValue());\n        }\n        if (type instanceof IntervalYearMonthType) {\n            return new SqlIntervalYearMonth(((Long) node.getValue()).intValue());\n        }\n        if (type.getJavaType().equals(Slice.class)) {\n            // DO NOT ever remove toBase64. Calling toString directly on Slice whose base is not byte[] will cause JVM to crash.\n            return \"'\" + VarbinaryFunctions.toBase64((Slice) node.getValue()).toStringUtf8() + \"'\";\n        }\n\n        // We should not fail at the moment; just return the raw value (block, regex, etc) to the user\n        return node.getValue();","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/planner/LiteralInterpreter.java#L141-L177","documentation":"LiteralInterpreter wraps failures while building a SqlTimestamp from a TIMESTAMP literal into GENERIC_USER_ERROR saying the value is not a valid timestamp literal. Thrown when the long value cannot be converted under the session's legacy/non-legacy timestamp settings.","triggerScenarios":"Evaluating a TIMESTAMP literal whose epoch-millis value fails SqlTimestamp construction (e.g. out-of-range or invalid under the session time zone / legacy timestamp mode).","commonSituations":"Mixed-version plans where literal encoding changed, extreme millisecond values, or legacy_timestamp session property mismatching how the literal was produced.","solutions":["Correct the timestamp literal to a valid value the session timezone can represent.","Align the legacy_timestamp session property with the server/connector expectations.","Re-plan/re-submit the query on the same Presto version that produced the plan."],"exampleFix":"// before\nSELECT TIMESTAMP '9999-99-99 99:99';\n// after\nSELECT TIMESTAMP '2026-01-01 00:00:00';","handlingStrategy":"validation","validationCode":"try { long millis = Long.parseLong(literalText); java.time.Instant.ofEpochMilli(millis); } catch (NumberFormatException | DateTimeException e) { /* reject literal before evaluation */ }","typeGuard":"boolean isValidTimestampMillis(long millis) { try { java.time.Instant.ofEpochMilli(millis); return true; } catch (DateTimeException e) { return false; } }","tryCatchPattern":"try { return LiteralInterpreter.evaluate(literal, session); } catch (PrestoException e) { if (e.getErrorCode() == StandardErrorCode.GENERIC_USER_ERROR.toErrorCode()) { /* prompt user to fix literal */ } else { throw e; } }","preventionTips":["Use valid, in-range TIMESTAMP literals","Keep legacy_timestamp session property consistent across environments","Re-plan queries on the same engine version that will execute them"],"tags":["literal","timestamp","user-error"],"backgroundTag":"invalid-literal-format","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"}