{"record":{"id":"d7bc20e7d9670330","repo":"prestodb/presto","slug":"expected-column-to-be-a-timestamp-type-but-is","errorCode":null,"errorMessage":"Expected column to be a timestamp type but is ","messagePattern":"Expected column to be a timestamp type but is ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":346,"sourceCode":"        if (columnInfo.getColumnTypeName().equalsIgnoreCase(\"timestamp\")) {\n            try {\n                return new Timestamp(TIMESTAMP_FORMATTER.withZone(localTimeZone).parseMillis(String.valueOf(value)));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SQLException(\"Invalid timestamp from server: \" + value, e);\n            }\n        }\n\n        if (columnInfo.getColumnTypeName().equalsIgnoreCase(\"timestamp with time zone\")) {\n            try {\n                return new Timestamp(TIMESTAMP_WITH_TIME_ZONE_FORMATTER.parseMillis(String.valueOf(value)));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SQLException(\"Invalid timestamp from server: \" + value, e);\n            }\n        }\n\n        throw new IllegalArgumentException(\"Expected column to be a timestamp type but is \" + columnInfo.getColumnTypeName());\n    }\n\n    @Override\n    public InputStream getAsciiStream(int columnIndex)\n            throws SQLException\n    {\n        throw new NotImplementedException(\"ResultSet\", \"getAsciiStream\");\n    }\n\n    @Override\n    public InputStream getUnicodeStream(int columnIndex)\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"getUnicodeStream\");\n    }\n\n    @Override\n    public InputStream getBinaryStream(int columnIndex)","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L328-L364","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nTimestamp ts = rs.getTimestamp(\"event_time\"); // event_time is varchar -> IllegalArgumentException\n// after\nString raw = rs.getString(\"event_time\");\nTimestamp ts = raw != null ? Timestamp.valueOf(raw) : null;\n// or in SQL: SELECT CAST(event_time AS timestamp) AS event_time","handlingStrategy":"validation","validationCode":"ResultSetMetaData md = rs.getMetaData();\nString typeName = md.getColumnTypeName(colIndex);\nif (!typeName.equalsIgnoreCase(\"timestamp\") && !typeName.equalsIgnoreCase(\"timestamp with time zone\")) {\n    throw new IllegalStateException(\"Column \" + colIndex + \" is not a timestamp but \" + typeName);\n}\nTimestamp ts = rs.getTimestamp(colIndex);","typeGuard":"static boolean isTimestampColumn(ResultSetMetaData md, int idx) throws SQLException {\n    String t = md.getColumnTypeName(idx);\n    return t != null && (t.equalsIgnoreCase(\"timestamp\") || t.equalsIgnoreCase(\"timestamp with time zone\"));\n}","tryCatchPattern":"Timestamp ts;\ntry {\n    ts = rs.getTimestamp(idx);\n} catch (IllegalArgumentException e) {\n    ts = Timestamp.valueOf(rs.getString(idx));\n}","preventionTips":["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"],"tags":["jdbc","presto","type-mismatch","resultset"],"backgroundTag":"jdbc-type-mismatch","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"}