{"record":{"id":"5d2c8b8ce22f8f66","repo":"apache/shardingsphere","slug":"underlying-sql-state-s-underlying-error-code-5d2c8b","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/PostgreSQLVarcharArrayValueParser.java","lineNumber":39,"sourceCode":"import org.apache.shardingsphere.infra.exception.external.sql.type.wrapper.SQLWrapperException;\nimport org.postgresql.util.PGobject;\n\nimport java.sql.SQLException;\n\n/**\n * Varchar array value parser of PostgreSQL.\n */\npublic final class PostgreSQLVarcharArrayValueParser implements PostgreSQLTextValueParser<PGobject> {\n    \n    @Override\n    public PGobject parse(final String value) {\n        try {\n            PGobject result = new PGobject();\n            result.setType(\"varchar[]\");\n            result.setValue(value);\n            return result;\n        } catch (final SQLException ex) {\n            throw new SQLWrapperException(ex);\n        }\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":43,"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/PostgreSQLVarcharArrayValueParser.java#L21-L43","documentation":"PostgreSQLVarcharArrayValueParser.parse builds a PGobject typed 'varchar[]'; any SQLException from setValue is wrapped in SQLWrapperException ('Underlying SQL state / error code' message). It triggers when a text bind parameter for a varchar[] column is not a valid PostgreSQL array literal.","triggerScenarios":"Binding values like \"'a','b'\" (missing braces), \"{a,'b}\" (unbalanced quoting), or elements with unescaped quotes/backslashes during extended-protocol bind for a varchar[] parameter.","commonSituations":"Hand-built array literals via string concatenation, values containing commas or braces inside elements that were never quoted/escaped, or copying array output from one driver into another.","solutions":["Use PreparedStatement.createArrayOf(\"varchar\", ...) or the driver's array support to build the literal","Quote and escape elements: \"{\\\"say \\\"hi\\\"\\\"}\" style per PostgreSQL array rules","Validate array literal syntax (balanced braces, escaped quotes) before binding","Read the wrapped SQLException code to locate the parse failure"],"exampleFix":"// before\nstmt.setString(1, \"'US','UK'\");\n// after\nstmt.setArray(1, conn.createArrayOf(\"varchar\", new String[]{\"US\",\"UK\"}));","handlingStrategy":"validation","validationCode":"boolean validVarcharArray(String s) { return s != null && s.matches(\"\\\\{.*\\\\}\") && balancedQuotesAndEscapes(s); }","typeGuard":null,"tryCatchPattern":"catch (SQLWrapperException e) { /* report invalid varchar[] literal with cause details */ }","preventionTips":["Build array parameters with createArrayOf","Escape quotes and backslashes inside elements","Test literals containing commas/quotes explicitly"],"tags":["postgresql","bind","array","varchar","value-parsing"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}