{"record":{"id":"0adae6b90b18e85e","repo":"prestodb/presto","slug":"expected-column-to-be-a-time-type-but-is","errorCode":null,"errorMessage":"Expected column to be a time type but is ","messagePattern":"Expected column to be a time type but is ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":309,"sourceCode":"        if (columnInfo.getColumnTypeName().equalsIgnoreCase(\"time\")) {\n            try {\n                return new Time(TIME_FORMATTER.withZone(localTimeZone).parseMillis(String.valueOf(value)));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SQLException(\"Invalid time from server: \" + value, e);\n            }\n        }\n\n        if (columnInfo.getColumnTypeName().equalsIgnoreCase(\"time with time zone\")) {\n            try {\n                return new Time(TIME_WITH_TIME_ZONE_FORMATTER.parseMillis(String.valueOf(value)));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SQLException(\"Invalid time from server: \" + value, e);\n            }\n        }\n\n        throw new IllegalArgumentException(\"Expected column to be a time type but is \" + columnInfo.getColumnTypeName());\n    }\n\n    @Override\n    public Timestamp getTimestamp(int columnIndex)\n            throws SQLException\n    {\n        return getTimestamp(columnIndex, sessionTimeZone);\n    }\n\n    private Timestamp getTimestamp(int columnIndex, DateTimeZone localTimeZone)\n            throws SQLException\n    {\n        Object value = column(columnIndex);\n        if (value == null) {\n            return null;\n        }\n\n        ColumnInfo columnInfo = columnInfo(columnIndex);","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L291-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nTime t = rs.getTime(idx); // idx is actually a TIMESTAMP column\n// after\nString typeName = rs.getMetaData().getColumnTypeName(idx);\nif (typeName.equalsIgnoreCase(\"time\") || typeName.equalsIgnoreCase(\"time with time zone\")) {\n    Time t = rs.getTime(idx);\n} else {\n    Timestamp ts = rs.getTimestamp(idx);\n    Time t = ts == null ? null : new Time(ts.getTime());\n}","handlingStrategy":"type-guard","validationCode":"String typeName = rs.getMetaData().getColumnTypeName(idx);\nboolean usable = \"time\".equalsIgnoreCase(typeName) || \"time with time zone\".equalsIgnoreCase(typeName);\nif (!usable) { /* use getDate/getTimestamp/getString instead */ }","typeGuard":"boolean isTimeLike(ResultSet rs, int idx) throws SQLException {\n    String t = rs.getMetaData().getColumnTypeName(idx);\n    return \"time\".equalsIgnoreCase(t) || \"time with time zone\".equalsIgnoreCase(t);\n}","tryCatchPattern":"try {\n    Time t = rs.getTime(idx);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Expected column to be a time type\")) {\n        Object v = rs.getObject(idx);\n        // convert based on actual type (Timestamp -> new Time(ts.getTime()), String -> parse)\n    } else { throw e; }\n}","preventionTips":["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"],"tags":["jdbc","presto","type-mismatch","sql"],"backgroundTag":"wrong-column-type-for-getter","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"}