{"record":{"id":"397377adf9613a66","repo":"apache/seatunnel","slug":"no-result-returned-after-running-query-minmaxqu","errorCode":null,"errorMessage":"No result returned after running query [${minMaxQuery}]","messagePattern":"No result returned after running query \\[(.+?)\\]","errorType":"exception","errorClass":"SQLException","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":78,"sourceCode":"\n    private PostgresUtils() {}\n\n    public static Object[] queryMinMax(\n            JdbcConnection jdbc, TableId tableId, String columnName, Column column)\n            throws SQLException {\n        columnName = quote(columnName);\n        if (column != null) {\n            columnName = JDBC_DIALECT.convertType(columnName, column.typeName());\n        }\n        final String minMaxQuery =\n                String.format(\n                        \"SELECT MIN(%s), MAX(%s) FROM %s\", columnName, columnName, quote(tableId));\n        return jdbc.queryAndMap(\n                minMaxQuery,\n                rs -> {\n                    if (!rs.next()) {\n                        // this should never happen\n                        throw new SQLException(\n                                String.format(\n                                        \"No result returned after running query [%s]\",\n                                        minMaxQuery));\n                    }\n                    return SourceRecordUtils.rowToArray(rs, 2);\n                });\n    }\n\n    public static long queryApproximateRowCnt(JdbcConnection jdbc, TableId tableId)\n            throws SQLException {\n        // The statement used to get approximate row count which is less\n        // accurate than COUNT(*), but is more efficient for large table.\n        final String rowCountQuery =\n                String.format(\n                        \"SELECT reltuples FROM pg_class r WHERE relkind = 'r' AND relname = '%s';\",\n                        tableId.table());\n        return jdbc.queryAndMap(\n                rowCountQuery,","sourceCodeStart":60,"sourceCodeEnd":96,"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#L60-L96","documentation":"PostgresUtils.queryMinMax runs 'SELECT MIN(col), MAX(col) FROM table' to compute a chunk-split boundary for incremental snapshots. If the ResultSet has no row at all, it throws SQLException 'No result returned after running query [..]'. The comment notes this should never happen, since aggregate queries normally return one row.","triggerScenarios":"rs.next() returns false for the MIN/MAX aggregate query — practically only when the JDBC driver/conn behaves abnormally, the query was cancelled before producing a row, or the statement failed in a way that returned an empty (not failed) result set.","commonSituations":"Very rare in practice; seen with driver quirks, cancelled statements, or when intercepting proxies return empty results. Worth handling defensively because the message includes the exact query for debugging.","solutions":["Run the embedded minMaxQuery (printed in the message) manually in psql to check the table/column","Verify the split column exists and the user can SELECT it","Retry the job — snapshot split planning will re-issue the query","If reproducible, check JDBC driver version compatibility with your Postgres server"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// run the aggregate manually before planning\nString q = String.format(\"SELECT MIN(%s), MAX(%s) FROM %s\", col, col, quotedTableId);","typeGuard":null,"tryCatchPattern":"try { minMax = PostgresUtils.queryMinMax(jdbc, tableId, col); } catch (SQLException e) { log.warn(\"empty result for {}\", e.getMessage()); }","preventionTips":["Verify split column exists and is SELECTable","Keep JDBC driver version matched to server version","Retry split planning on transient failures"],"tags":["postgres","jdbc","query","snapshot"],"backgroundTag":"empty-result-set","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}