{"record":{"id":"087959730b741e0d","repo":"prestodb/presto","slug":"invalid-timestamp-from-server","errorCode":null,"errorMessage":"Invalid timestamp from server: ","messagePattern":"Invalid timestamp from server: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":333,"sourceCode":"    {\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);\n        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","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L315-L351","documentation":"Thrown by PrestoResultSet.getTimestamp when a TIMESTAMP column value cannot be parsed by TIMESTAMP_FORMATTER.withZone(localTimeZone).parseMillis. The raw server string is included in the message alongside the wrapped IllegalArgumentException. It signals a value outside the expected ISO 'yyyy-MM-dd HH:mm:ss[.SSS]' format.","triggerScenarios":"Calling ResultSet.getTimestamp(columnIndex) on a 'timestamp' column whose value is empty, null-string, or non-ISO (e.g. '0000-00-00 00:00:00', epoch numbers, or locale-formatted dates).","commonSituations":"Custom connectors emitting epoch milliseconds or alternate formats; data polluted by other ETL tools; client/server version mismatch changing timestamp wire format; legacy zero dates surfaced through a Presto connector.","solutions":["Read the raw value from the exception message and verify it against the expected ISO format.","Handle NULL first with wasNull() so an empty string is not fed to the parser.","Align presto-jdbc driver version with the Presto server version.","Normalize in SQL (CAST(col AS timestamp) or date_parse/format_datetime) before fetching.","Fall back to getString and parse with a custom DateTimeFormatter matching the actual format."],"exampleFix":"// before\nTimestamp ts = rs.getTimestamp(4);\n// after\nString raw = rs.getString(4);\nTimestamp ts = null;\nif (raw != null) {\n    try { ts = rs.getTimestamp(4); }\n    catch (SQLException e) {\n        long epoch = Long.parseLong(raw.trim()); // e.g. server sent epoch millis\n        ts = new Timestamp(epoch);\n    }\n}","handlingStrategy":"try-catch","validationCode":"String typeName = rs.getMetaData().getColumnTypeName(idx);\nString raw = rs.getString(idx);\nboolean safe = \"timestamp\".equalsIgnoreCase(typeName) && raw != null && raw.trim().matches(\"\\\\d{4}-\\\\d{2}-\\\\d{2}[ T]\\\\d{2}:\\\\d{2}:\\\\d{2}(\\\\.\\\\d{1,9})?\");","typeGuard":"boolean isTimestampColumn(ResultSet rs, int idx) throws SQLException {\n    return \"timestamp\".equalsIgnoreCase(rs.getMetaData().getColumnTypeName(idx));\n}","tryCatchPattern":"try {\n    Timestamp ts = rs.getTimestamp(idx);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid timestamp from server:\")) {\n        String raw = rs.getString(idx);\n        // custom parse (epoch millis, alternate formatter) or log-and-null\n    } else { throw e; }\n}","preventionTips":["Guard NULLs with wasNull() before getTimestamp","Repair non-ISO strings (zero dates, epoch numbers) at query time with CAST","Keep driver/server versions consistent","Parse with a custom DateTimeFormatter via getString when the source data is known to be non-ISO"],"tags":["jdbc","presto","timestamp-parsing","sql"],"backgroundTag":"invalid-timestamp-format-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"}