prestodb/presto · error · SemanticException
INVALID_LITERAL
INVALID_LITERAL
Error message
'%s' is not a valid timestamp literal
What it means
Literal interpretation error: the text of a timestamp literal could not be parsed by Presto's timestamp parser in either legacy-timestamp (time-zone-aware) or default mode. The %s is the literal text as written in the query; the faulty input is the TIMESTAMP '...' literal itself.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LiteralInterpreter.java:300
return parseTimeLiteral(node.getValue());
}
}
@Override
protected Long visitTimestampLiteral(TimestampLiteral node, ConnectorSession session)
{
SqlFunctionProperties properties = session.getSqlFunctionProperties();
try {
if (properties.isLegacyTimestamp()) {
return parseTimestampLiteral(properties.getTimeZoneKey(), node.getValue());
}
else {
return parseTimestampLiteral(node.getValue());
}
}
catch (RuntimeException e) {
throw new SemanticException(INVALID_LITERAL, node, "'%s' is not a valid timestamp literal", node.getValue());
}
}
@Override
protected Long visitIntervalLiteral(IntervalLiteral node, ConnectorSession session)
{
if (node.isYearToMonth()) {
return node.getSign().multiplier() * parseYearMonthInterval(node.getValue(), node.getStartField(), node.getEndField());
}
else {
return node.getSign().multiplier() * parseDayTimeInterval(node.getValue(), node.getStartField(), node.getEndField());
}
}
@Override
protected Object visitNullLiteral(NullLiteral node, ConnectorSession session)
{
return null;View on GitHub (pinned to 55bb57d202)
Solutions
- Correct the literal to ISO 8601 format: TIMESTAMP 'YYYY-MM-DD HH:MM:SS[.fff]'.
- Verify the date components are valid and in range.
- Check legacy timestamp session property if parsing differs between environments.
Example fix
// before SELECT TIMESTAMP '2026/13/45'; // after SELECT TIMESTAMP '2026-01-01 12:00:00';
Defensive patterns
Strategy: validation
Validate before calling
try { java.time.LocalDateTime.parse(text, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.SSS]")); } catch (DateTimeParseException e) { /* invalid TIMESTAMP literal text */ } Type guard
boolean isValidTimestampText(String text) { try { java.time.LocalDateTime.parse(text.replace('T', ' '), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.SSS]")); return true; } catch (DateTimeParseException e) { return false; } } Try / catch
try { return visitTimestampLiteral(node, session); } catch (SemanticException e) { if (e.getCode() == INVALID_LITERAL) { /* surface message with the offending text */ } else { throw e; } } Prevention
- Write TIMESTAMP literals in ISO 8601: 'YYYY-MM-DD HH:MM:SS[.fff]'
- Validate date components (month 1-12, day valid for month) before submitting
- Watch out for legacy vs new timestamp parsing differences between sessions
When it happens
Trigger: Evaluating TIMESTAMP '<text>' where parseTimestampLiteral (or legacy path) throws at runtime — bad format, invalid dates like month 13, missing components.
Common situations: Copy-pasted dates with wrong separators, ambiguous formats (legacy vs new timestamp parsing), locale assumptions, out-of-range values.
Related errors
- INVALID_LITERAL
- GENERIC_USER_ERROR
- TimestampWithTimeZone overflow: %s ms
- Precision not supported
- nanos must be in range [0, 999_999_999]:
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/9f10548ad596abfc.
Report an issue: GitHub.