{"record":{"id":"b8cc79d48c8803eb","repo":"apache/shardingsphere","slug":"underlying-sql-state-s-underlying-error-code-b8cc79","errorCode":null,"errorMessage":"Underlying SQL state: %s, underlying error code: %s.","messagePattern":"Underlying SQL state: (.+?), underlying error code: (.+?)\\.","errorType":"exception","errorClass":"SQLWrapperException","httpStatus":null,"severity":"error","filePath":"database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLTimestampValueParser.java","lineNumber":56,"sourceCode":"                    + \"[HH:mm:ss][HHmmss][HH:mm][HHmm]\"\n                    + \"[.SSSSSSSSS][.SSSSSSSS][.SSSSSSS][.SSSSSS][.SSSSS][.SSSS][.SSS][.SS][.S]\"\n                    + \"[ ]\"\n                    + \"[XXXXX][XXXX][XXX][XX][X]\");\n    \n    @Override\n    public Timestamp parse(final String value) {\n        try {\n            return Timestamp.valueOf(LocalDateTime.from(POSTGRESQL_DATE_TIME_FORMATTER.parse(value)));\n        } catch (final DateTimeParseException ignored) {\n            return fallbackToPostgreSQLTimestampUtils(value);\n        }\n    }\n    \n    private static Timestamp fallbackToPostgreSQLTimestampUtils(final String value) {\n        try {\n            return new TimestampUtils(false, null).toTimestamp(null, value);\n        } catch (final SQLException ex) {\n            throw new SQLWrapperException(ex);\n        }\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLTimestampValueParser.java#L38-L60","documentation":"PostgreSQLTimestampValueParser.parse tries a strict formatter, then falls back to TimestampUtils.toTimestamp; when both fail, the SQLException is wrapped in SQLWrapperException ('Underlying SQL state / error code' message). It triggers when a text bind parameter for a timestamp column cannot be parsed by either path.","triggerScenarios":"Binding values like 'yesterday', '2024-13-45 99:00:00', 'DD-MM-YYYY HH:mm' style locale strings, or BCE/infinity spellings the default TimestampUtils(false, null) configuration rejects.","commonSituations":"Locale-dependent timestamp strings, applications assuming lenient parsing, or special PostgreSQL values ('infinity', 'now') that a non-calendar TimestampUtils without interval support refuses.","solutions":["Send timestamps in ISO-8601 form (yyyy-MM-dd HH:mm:ss[.fff])","Bind java.sql.Timestamp / LocalDateTime typed parameters instead of raw strings","Check the wrapped SQLException state/code for the exact rejection reason","Pre-validate with Timestamp.valueOf or LocalDateTime.parse on the client"],"exampleFix":"// before\nstmt.setString(1, \"31-12-2024 23:59\");\n// after\nstmt.setTimestamp(1, java.sql.Timestamp.valueOf(\"2024-12-31 23:59:00\"));","handlingStrategy":"validation","validationCode":"try { java.time.LocalDateTime.parse(value.replace(' ', 'T')); return true; } catch (java.time.format.DateTimeParseException e) { return false; }","typeGuard":null,"tryCatchPattern":"catch (SQLWrapperException e) { SQLException c = (SQLException) e.getCause(); /* classify via c.getSQLState() */ }","preventionTips":["Use ISO-8601 timestamps","Bind java.sql.Timestamp instead of strings","Avoid special values ('now', 'infinity') through the proxy bind path"],"tags":["postgresql","bind","timestamp","value-parsing"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}