{"record":{"id":"2b3fa11874130bb7","repo":"apache/shardingsphere","slug":"underlying-sql-state-s-underlying-error-code-2b3fa1","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/PostgreSQLTextArrayValueParser.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 * Text array value parser of PostgreSQL.\n */\npublic final class PostgreSQLTextArrayValueParser implements PostgreSQLTextValueParser<PGobject> {\n    \n    @Override\n    public PGobject parse(final String value) {\n        try {\n            PGobject result = new PGobject();\n            result.setType(\"text[]\");\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/PostgreSQLTextArrayValueParser.java#L21-L43","documentation":"PostgreSQLTextArrayValueParser.parse constructs a PGobject typed 'text[]'; a SQLException during setValue is wrapped in SQLWrapperException with the 'Underlying SQL state / error code' message. It triggers when a text bind parameter for a text[] column is not a valid PostgreSQL array literal.","triggerScenarios":"Binding values like '{a,b' (unclosed brace), 'a,b,c' (missing array braces), nested-quote mistakes like '{\"x}', or stray backslashes during extended-protocol bind for a text[] parameter.","commonSituations":"Applications building array literals by hand with string concatenation, forgetting the {..} wrapper, or mishandling embedded commas/quotes in elements.","solutions":["Build array literals with a helper (e.g. org.postgresql.jdbc PgArray or PreparedStatement.createArrayOf) instead of string concatenation","Wrap the value in braces and quote elements containing commas/braces: \"{a,b}\"","Validate the literal against PostgreSQL array syntax before binding","Inspect the wrapped SQLException for the exact parse position"],"exampleFix":"// before\nstmt.setString(1, \"red,green\");\n// after\nstmt.setArray(1, conn.createArrayOf(\"text\", new String[]{\"red\",\"green\"}));","handlingStrategy":"validation","validationCode":"boolean validPgArray(String s) { return s != null && s.startsWith(\"{\") && s.endsWith(\"}\") && balancedQuotes(s); }","typeGuard":null,"tryCatchPattern":"catch (SQLWrapperException e) { /* log cause SQLState; tell caller the array literal is malformed */ }","preventionTips":["Use conn.createArrayOf(...) instead of hand-built literals","Quote elements containing commas, braces or quotes","Add unit tests for array parameter construction"],"tags":["postgresql","bind","array","value-parsing"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}