{"record":{"id":"3028347c80c5208b","repo":"prestodb/presto","slug":"invalid-date-from-server","errorCode":null,"errorMessage":"Invalid date from server: ","messagePattern":"Invalid date from server: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":271,"sourceCode":"    public Date getDate(int columnIndex)\n            throws SQLException\n    {\n        return getDate(columnIndex, sessionTimeZone);\n    }\n\n    private Date getDate(int columnIndex, DateTimeZone localTimeZone)\n            throws SQLException\n    {\n        Object value = column(columnIndex);\n        if (value == null) {\n            return null;\n        }\n\n        try {\n            return new Date(DATE_FORMATTER.withZone(localTimeZone).parseMillis(String.valueOf(value)));\n        }\n        catch (IllegalArgumentException e) {\n            throw new SQLException(\"Invalid date from server: \" + value, e);\n        }\n    }\n\n    @Override\n    public Time getTime(int columnIndex)\n            throws SQLException\n    {\n        return getTime(columnIndex, sessionTimeZone);\n    }\n\n    private Time getTime(int columnIndex, DateTimeZone localTimeZone)\n            throws SQLException\n    {\n        Object value = column(columnIndex);\n        if (value == null) {\n            return null;\n        }\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L253-L289","documentation":"getDate(columnIndex) parses the column's value as an ISO date (yyyy-MM-dd) in the session time zone using DATE_FORMATTER. If the value cannot be parsed (IllegalArgumentException), the driver throws SQLException(\"Invalid date from server: \" + value). This means the column contained something other than a DATE-typed value, typically because the caller asked getDate on a non-date column (string, timestamp, varchar).","triggerScenarios":"Calling getDate on a column that is not of Presto type DATE — e.g. a VARCHAR holding arbitrary text, a TIMESTAMP value, or NULL-formatted/nonstandard text produced by the query (getDate(int, Calendar) delegates to the same code path).","commonSituations":"Schema drift after a table column changed from DATE to VARCHAR/TIMESTAMP; using column position after changing the SELECT list; timestamps with time components or strings like '2024-01-01T00:00:00' fed to getDate; dynamic queries where column order is not guaranteed.","solutions":["Verify the column type in the query result and call the matching getter (getString, getTimestamp, getDate accordingly)","If the value is a timestamp string, either cast to DATE in SQL (CAST(col AS DATE)) or read it with getTimestamp","Reference columns by name/alias rather than index to survive SELECT-list changes","Validate/normalize VARCHAR date text in SQL (date_parse/coalesce) before the driver parses it"],"exampleFix":"// before\nDate d = rs.getDate(\"created_at\"); // created_at is TIMESTAMP -> throws\n// after\nDate d = rs.getDate(\"created_date\"); // a CAST(created_at AS DATE) AS created_date column","handlingStrategy":"type-guard","validationCode":"ResultSetMetaData md = rs.getMetaData();\nif (md.getColumnType(colIdx) == Types.DATE) {\n    Date d = rs.getDate(colIdx);\n}","typeGuard":"Date safeGetDate(ResultSet rs, String col) throws SQLException {\n    ResultSetMetaData md = rs.getMetaData();\n    int idx = rs.findColumn(col);\n    if (md.getColumnType(idx) != Types.DATE) return null; // not a DATE column\n    return rs.getDate(idx);\n}","tryCatchPattern":"catch (SQLException e) {\n    if (e.getMessage().startsWith(\"Invalid date from server\")) {\n        // fall back to getString and parse defensively, or fix the column type\n        String raw = rs.getString(col);\n    }\n    throw e;\n}","preventionTips":["Call getDate only on DATE-typed columns; use getTimestamp/getObject for TIMESTAMP and getString for VARCHAR","Check ResultSetMetaData column types before choosing a getter","Reference columns by alias/name, not positional index, to survive SELECT-list edits","CAST or normalize non-DATE values in SQL before the driver parses them"],"tags":["jdbc","resultset","date-parsing","type-mismatch"],"backgroundTag":"invalid-date-value-from-server","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"}