{"record":{"id":"dae3cc617b630bff","repo":"apache/seatunnel","slug":"failed-to-build-the-split-data-read-statement-dae3cc","errorCode":null,"errorMessage":"Failed to build the split data read statement.","messagePattern":"Failed to build the split data read statement\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/utils/PostgresUtils.java","lineNumber":364,"sourceCode":"            if (isFirstSplit) {\n                for (int i = 0; i < primaryKeyNum; i++) {\n                    statement.setObject(i + 1, splitEnd[i]);\n                    statement.setObject(i + 1 + primaryKeyNum, splitEnd[i]);\n                }\n            } else if (isLastSplit) {\n                for (int i = 0; i < primaryKeyNum; i++) {\n                    statement.setObject(i + 1, splitStart[i]);\n                }\n            } else {\n                for (int i = 0; i < primaryKeyNum; i++) {\n                    statement.setObject(i + 1, splitStart[i]);\n                    statement.setObject(i + 1 + primaryKeyNum, splitEnd[i]);\n                    statement.setObject(i + 1 + 2 * primaryKeyNum, splitEnd[i]);\n                }\n            }\n            return statement;\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to build the split data read statement.\", e);\n        }\n    }\n\n    private static String getPrimaryKeyColumnsProjection(SeaTunnelRowType rowType) {\n        StringBuilder sql = new StringBuilder();\n        for (Iterator<String> fieldNamesIt = Arrays.stream(rowType.getFieldNames()).iterator();\n                fieldNamesIt.hasNext(); ) {\n            sql.append(fieldNamesIt.next());\n            if (fieldNamesIt.hasNext()) {\n                sql.append(\" , \");\n            }\n        }\n        return sql.toString();\n    }\n\n    private static String buildSplitQuery(\n            Table table,\n            SeaTunnelRowType rowType,","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-postgres/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/postgres/utils/PostgresUtils.java#L346-L382","documentation":"A generic RuntimeException wrapping any failure while building the PreparedStatement that reads rows for a snapshot split (primary-key range query). Any SQL construction, parameter binding, or driver error during statement creation is reported with this message.","triggerScenarios":"PostgresUtils.readTableSplitDataStatement(...) fails when setObject() rejects a split boundary value type, the rowType/primaryKey columns are mismatched, or the generated SQL is invalid (e.g. missing primary key columns, bad quoting).","commonSituations":"Tables with exotic primary-key column types (JSONB, arrays, UUID) that the JDBC driver cannot bind via setObject; split boundaries computed from incompatible schema snapshots; malformed table identifiers after case-folding.","solutions":["Inspect the wrapped cause 'e' in the stack trace — it contains the real driver error","Verify the table has a usable primary key and its columns appear in the configured rowType","Check split boundary values are of types the Postgres JDBC driver can bind","Update the Postgres JDBC driver to the latest version","If a custom type is the cause, exclude that column from the split key or handle it via type mapping"],"exampleFix":"// before\nstatement.setObject(i + 1, splitStart[i]); // fails for UUID/JSONB\n// after\nObject v = splitStart[i];\nif (v instanceof java.util.UUID) {\n    statement.setObject(i + 1, v, java.sql.Types.OTHER);\n} else {\n    statement.setObject(i + 1, v);\n}","handlingStrategy":"try-catch","validationCode":"// preflight: check primary key columns exist and types are bindable\nfor (String pk : primaryKeyColumns) {\n    int idx = rowType.indexOf(pk);\n    if (idx < 0) throw new IllegalArgumentException(\"PK column missing from rowType: \" + pk);\n}","typeGuard":null,"tryCatchPattern":"try {\n    stmt = PostgresUtils.readTableSplitDataStatement(jdbc, querySql, splitStart, splitEnd, pkCols);\n} catch (RuntimeException e) {\n    throw new RuntimeException(\"split statement build failed: \" + e.getMessage(), e);\n}","preventionTips":["Ensure tables have simple, supported primary-key types (int, bigint, text)","Keep the schema snapshot used for splitting in sync with the live table schema","Keep the Postgres JDBC driver up to date","Avoid exotic PK types (JSONB, arrays, UUID) or map them explicitly"],"tags":["jdbc","postgres","cdc","sql","statement"],"backgroundTag":"sql-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}