prestodb/presto · error · SQLException

Invalid time from server:

Error message

Invalid time from server: 

What it means

Thrown by PrestoResultSet.getTime when a TIME column value returned by the Presto server cannot be parsed by Joda-Time's ISO time parser. The SQLException wraps the underlying IllegalArgumentException from parseMillis and includes the offending raw value. It indicates the server sent a string that does not match the expected ISO 'HH:mm:ss[.SSS]' time format.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:296

    {
        return getTime(columnIndex, sessionTimeZone);
    }

    private Time getTime(int columnIndex, DateTimeZone localTimeZone)
            throws SQLException
    {
        Object value = column(columnIndex);
        if (value == null) {
            return null;
        }

        ColumnInfo columnInfo = columnInfo(columnIndex);
        if (columnInfo.getColumnTypeName().equalsIgnoreCase("time")) {
            try {
                return new Time(TIME_FORMATTER.withZone(localTimeZone).parseMillis(String.valueOf(value)));
            }
            catch (IllegalArgumentException e) {
                throw new SQLException("Invalid time from server: " + value, e);
            }
        }

        if (columnInfo.getColumnTypeName().equalsIgnoreCase("time with time zone")) {
            try {
                return new Time(TIME_WITH_TIME_ZONE_FORMATTER.parseMillis(String.valueOf(value)));
            }
            catch (IllegalArgumentException e) {
                throw new SQLException("Invalid time from server: " + value, e);
            }
        }

        throw new IllegalArgumentException("Expected column to be a time type but is " + columnInfo.getColumnTypeName());
    }

    @Override
    public Timestamp getTimestamp(int columnIndex)
            throws SQLException

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the offending value embedded in the SQLException message to see what the server actually returned.
  2. Verify the column is truly Presto type 'time' and the value is non-null; handle NULL with wasNull() before calling getTime.
  3. Upgrade the presto-jdbc driver to match the server version so serialization formats agree.
  4. If the value is non-ISO, cast in SQL (e.g. CAST(col AS time) or date_format/parse) to normalize before fetching.
  5. Catch SQLException and fall back to getString plus custom parsing.

Example fix

// before
Time t = rs.getTime(3);
// after
String raw = rs.getString(3);
Time t = null;
if (raw != null) {
    try { t = rs.getTime(3); }
    catch (SQLException e) {
        java.time.LocalTime lt = java.time.LocalTime.parse(raw.trim()); // custom fallback parse
        t = Time.valueOf(lt);
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

String typeName = rs.getMetaData().getColumnTypeName(idx);
String raw = rs.getString(idx);
boolean safe = "time".equalsIgnoreCase(typeName) && raw != null && raw.trim().matches("\\d{1,2}:\\d{2}:\\d{2}(\\.\\d{1,9})?");

Type guard

boolean isTimeColumn(ResultSet rs, int idx) throws SQLException {
    String t = rs.getMetaData().getColumnTypeName(idx);
    return "time".equalsIgnoreCase(t);
}

Try / catch

try {
    Time t = rs.getTime(idx);
} catch (SQLException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Invalid time from server:")) {
        String raw = rs.getString(idx);
        // fallback: parse raw with a custom formatter or log and treat as null
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling ResultSet.getTime(columnIndex) on a column whose server value is null, empty, or formatted in a non-ISO form (e.g. '24:00:00', trailing garbage, or a locale-formatted string) while the column type name is 'time'.

Common situations: Queries through intermediate proxies or non-Presto backends returning differently formatted times; custom connectors emitting non-ISO time strings; driver/server version mismatch changing serialization format.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/b3477830c2498b72. Report an issue: GitHub.