prestodb/presto · error · IllegalArgumentException
Expected column to be a time type but is
Error message
Expected column to be a time type but is
What it means
An IllegalArgumentException (not SQLException) thrown by PrestoResultSet.getTime when the requested column is neither 'time' nor 'time with time zone' per the result-set metadata. It means getTime() was called on a column of a different SQL type; no implicit coercion is performed.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:309
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
{
return getTimestamp(columnIndex, sessionTimeZone);
}
private Timestamp getTimestamp(int columnIndex, DateTimeZone localTimeZone)
throws SQLException
{
Object value = column(columnIndex);
if (value == null) {
return null;
}
ColumnInfo columnInfo = columnInfo(columnIndex);View on GitHub (pinned to 55bb57d202)
Solutions
- Check ResultSetMetaData.getColumnType(columnIndex) / getColumnTypeName before calling getTime.
- Switch to the correct column index or use getTimestamp/getDate/getString appropriate to the actual type.
- Cast in SQL to TIME if the source column is varchar/timestamp: CAST(col AS time).
- Reference columns by name and keep a fixed, tested projection list to avoid index drift.
Example fix
// before
Time t = rs.getTime(idx); // idx is actually a TIMESTAMP column
// after
String typeName = rs.getMetaData().getColumnTypeName(idx);
if (typeName.equalsIgnoreCase("time") || typeName.equalsIgnoreCase("time with time zone")) {
Time t = rs.getTime(idx);
} else {
Timestamp ts = rs.getTimestamp(idx);
Time t = ts == null ? null : new Time(ts.getTime());
} Defensive patterns
Strategy: type-guard
Validate before calling
String typeName = rs.getMetaData().getColumnTypeName(idx);
boolean usable = "time".equalsIgnoreCase(typeName) || "time with time zone".equalsIgnoreCase(typeName);
if (!usable) { /* use getDate/getTimestamp/getString instead */ } Type guard
boolean isTimeLike(ResultSet rs, int idx) throws SQLException {
String t = rs.getMetaData().getColumnTypeName(idx);
return "time".equalsIgnoreCase(t) || "time with time zone".equalsIgnoreCase(t);
} Try / catch
try {
Time t = rs.getTime(idx);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Expected column to be a time type")) {
Object v = rs.getObject(idx);
// convert based on actual type (Timestamp -> new Time(ts.getTime()), String -> parse)
} else { throw e; }
} Prevention
- Always check ResultSetMetaData.getColumnType/getColumnTypeName before time getters
- Avoid SELECT * with positional indexes in evolving schemas
- Select explicit CAST(col AS time) when the source column is another type
- Use column-name lookups and a fixed, tested projection list
When it happens
Trigger: Calling ResultSet.getTime(columnIndex) on DATE, TIMESTAMP, VARCHAR, BIGINT or any non-time column; commonly caused by a wrong column index or an unnoticed schema change in the query.
Common situations: SELECT * column ordering changed after schema changes; using positional indexes across modified queries; expecting implicit coercion from varchar/timestamp to Time which Presto JDBC does not perform.
Related errors
- No wrapper for
- Invalid time from server:
- Invalid timestamp from server:
- Expected column to be a timestamp type but is
- INVALID_TABLE_PROPERTY
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/0adae6b90b18e85e.
Report an issue: GitHub.