apache/shardingsphere · error · SQLWrapperException
Underlying SQL state: %s, underlying error code: %s.
Error message
Underlying SQL state: %s, underlying error code: %s.
What it means
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.
Source
Thrown at database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLVarcharArrayValueParser.java:39
import org.apache.shardingsphere.infra.exception.external.sql.type.wrapper.SQLWrapperException;
import org.postgresql.util.PGobject;
import java.sql.SQLException;
/**
* Varchar array value parser of PostgreSQL.
*/
public final class PostgreSQLVarcharArrayValueParser implements PostgreSQLTextValueParser<PGobject> {
@Override
public PGobject parse(final String value) {
try {
PGobject result = new PGobject();
result.setType("varchar[]");
result.setValue(value);
return result;
} catch (final SQLException ex) {
throw new SQLWrapperException(ex);
}
}
}
View on GitHub (pinned to e952770a21)
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
Example fix
// before
stmt.setString(1, "'US','UK'");
// after
stmt.setArray(1, conn.createArrayOf("varchar", new String[]{"US","UK"})); Defensive patterns
Strategy: validation
Validate before calling
boolean validVarcharArray(String s) { return s != null && s.matches("\\{.*\\}") && balancedQuotesAndEscapes(s); } Try / catch
catch (SQLWrapperException e) { /* report invalid varchar[] literal with cause details */ } Prevention
- Build array parameters with createArrayOf
- Escape quotes and backslashes inside elements
- Test literals containing commas/quotes explicitly
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Underlying SQL state: %s, underlying error code: %s.
- Underlying SQL state: %s, underlying error code: %s.
- Underlying SQL state: %s, underlying error code: %s.
- Underlying SQL state: %s, underlying error code: %s.
- Unsupported time format: [%s]
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/5d2c8b8ce22f8f66.
Report an issue: GitHub.