prestodb/presto · error · IllegalArgumentException
Expected column to be a timestamp type but is
Error message
Expected column to be a timestamp type but is
What it means
PrestoResultSet.getTimestamp parses the column only when the column's reported type name is 'timestamp' or 'timestamp with time zone'. If the column holds any other Presto type, the driver throws an IllegalArgumentException naming the actual server type. It signals a caller bug: getTimestamp was invoked on a non-timestamp column instead of using the matching getter.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:346
if (columnInfo.getColumnTypeName().equalsIgnoreCase("timestamp")) {
try {
return new Timestamp(TIMESTAMP_FORMATTER.withZone(localTimeZone).parseMillis(String.valueOf(value)));
}
catch (IllegalArgumentException e) {
throw new SQLException("Invalid timestamp from server: " + value, e);
}
}
if (columnInfo.getColumnTypeName().equalsIgnoreCase("timestamp with time zone")) {
try {
return new Timestamp(TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseMillis(String.valueOf(value)));
}
catch (IllegalArgumentException e) {
throw new SQLException("Invalid timestamp from server: " + value, e);
}
}
throw new IllegalArgumentException("Expected column to be a timestamp type but is " + columnInfo.getColumnTypeName());
}
@Override
public InputStream getAsciiStream(int columnIndex)
throws SQLException
{
throw new NotImplementedException("ResultSet", "getAsciiStream");
}
@Override
public InputStream getUnicodeStream(int columnIndex)
throws SQLException
{
throw new SQLFeatureNotSupportedException("getUnicodeStream");
}
@Override
public InputStream getBinaryStream(int columnIndex)View on GitHub (pinned to 55bb57d202)
Solutions
- Read the column with the getter matching its actual Presto type (getString/getDate for date/varchar, getLong for bigint)
- Cast in SQL: SELECT CAST(col AS timestamp) or CAST(col AS timestamp with time zone)
- Branch on ResultSetMetaData.getColumnTypeName(i) before choosing a getter
- Fix upstream schema drift so the column is genuinely timestamp typed
Example fix
// before
Timestamp ts = rs.getTimestamp("event_time"); // event_time is varchar -> IllegalArgumentException
// after
String raw = rs.getString("event_time");
Timestamp ts = raw != null ? Timestamp.valueOf(raw) : null;
// or in SQL: SELECT CAST(event_time AS timestamp) AS event_time Defensive patterns
Strategy: validation
Validate before calling
ResultSetMetaData md = rs.getMetaData();
String typeName = md.getColumnTypeName(colIndex);
if (!typeName.equalsIgnoreCase("timestamp") && !typeName.equalsIgnoreCase("timestamp with time zone")) {
throw new IllegalStateException("Column " + colIndex + " is not a timestamp but " + typeName);
}
Timestamp ts = rs.getTimestamp(colIndex); Type guard
static boolean isTimestampColumn(ResultSetMetaData md, int idx) throws SQLException {
String t = md.getColumnTypeName(idx);
return t != null && (t.equalsIgnoreCase("timestamp") || t.equalsIgnoreCase("timestamp with time zone"));
} Try / catch
Timestamp ts;
try {
ts = rs.getTimestamp(idx);
} catch (IllegalArgumentException e) {
ts = Timestamp.valueOf(rs.getString(idx));
} Prevention
- Check ResultSetMetaData.getColumnTypeName before choosing getters
- Cast non-timestamp columns to timestamp in the SQL query
- Avoid generic mappers that call getTimestamp unconditionally
- Add tests covering the actual Presto types your queries return
When it happens
Trigger: Calling ResultSet.getTimestamp(i) or getTimestamp(label) on a column whose Presto type is not timestamp/timestamp with time zone (e.g. date, varchar, bigint, map, row). Also occurs after schema drift changes a column from timestamp to another type while the code still calls getTimestamp.
Common situations: Code that calls getTimestamp on a 'date' or varchar column; SELECT with CAST(col AS varchar) of a timestamp read via getTimestamp; schema evolution in upstream tables; generic result-set mappers that call getTimestamp unconditionally.
Related errors
- No wrapper for
- Result set type must be TYPE_FORWARD_ONLY
- Result set concurrency must be CONCUR_READ_ONLY
- Invalid date from server:
- Expected column to be a time type but is
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/d7bc20e7d9670330.
Report an issue: GitHub.