{"record":{"id":"bc3ae8cbfd3f5748","repo":"apache/seatunnel","slug":"common-sql-operation-failed-bc3ae8","errorCode":"COMMON_SQL_OPERATION_FAILED","errorMessage":"Sql command: ","messagePattern":"Sql command: ","errorType":"error_code","errorClass":"JdbcConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/executor/CopyManagerBatchStatementExecutor.java","lineNumber":185,"sourceCode":"                case ARRAY:\n                case ROW:\n                default:\n                    throw new JdbcConnectorException(\n                            CommonErrorCodeDeprecated.UNSUPPORTED_DATA_TYPE,\n                            \"Unexpected value: \" + seaTunnelDataType);\n            }\n        }\n        return csvRecord;\n    }\n\n    @Override\n    public void executeBatch() throws SQLException {\n        try {\n            this.csvPrinter.flush();\n            this.copyManagerProxy.doCopy(\n                    copySql, new StringReader(this.csvPrinter.getOut().toString()));\n        } catch (InvocationTargetException | IllegalAccessException | IOException e) {\n            throw new JdbcConnectorException(\n                    CommonErrorCodeDeprecated.SQL_OPERATION_FAILED, \"Sql command: \" + copySql);\n        } finally {\n            try {\n                this.csvPrinter.close();\n                this.csvPrinter = new CSVPrinter(new StringBuilder(), csvFormat);\n            } catch (Exception ignore) {\n            }\n        }\n    }\n\n    @Override\n    public void closeStatements() throws SQLException {\n        this.copyManagerProxy = null;\n        try {\n            this.csvPrinter.close();\n            this.csvPrinter = null;\n        } catch (Exception ignore) {\n        }","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/executor/CopyManagerBatchStatementExecutor.java#L167-L203","documentation":"After buffering rows as CSV, executeBatch invokes the underlying COPY command via CopyManagerProxy.doCopy. If that reflective call throws (InvocationTargetException, IllegalAccessException) or the CSV buffer cannot be read (IOException), the exception is wrapped in this SQL_OPERATION_FAILED error whose message carries the COPY SQL statement.","triggerScenarios":"Calling executeBatch on CopyManagerBatchStatementExecutor when the database rejects the COPY statement (syntax/permissions), the connection is broken, or serialization of the CSV buffer fails.","commonSituations":"User lacks table COPY privileges on PostgreSQL; the copy SQL template does not match the actual table columns; network drop mid-copy; CSV contains characters that break the configured format.","solutions":["Read the cause (InvocationTargetException target) for the real database error; fix the underlying SQL/permission problem.","Verify the user has COPY privileges on the target table.","Confirm the copy SQL matches the table's column list and the CSVFormat's delimiter/quote settings.","Check connection health and retry; increase socket/network timeouts for large batches."],"exampleFix":"// before\nurl = \"jdbc:postgresql://host:5432/db\"\n// after: grant COPY rights and verify table columns\n// GRANT INSERT ON target_table TO etl_user;","handlingStrategy":"try-catch","validationCode":"// preflight: verify privileges and table shape\n// SELECT has_table_privilege('etl_user','target_table','INSERT');","typeGuard":null,"tryCatchPattern":"try {\n  executor.executeBatch();\n} catch (JdbcConnectorException e) {\n  if (CommonErrorCodeDeprecated.SQL_OPERATION_FAILED.equals(e.getErrorCode()) && e.getCause() instanceof InvocationTargetException) {\n    Throwable dbErr = e.getCause().getCause();\n    log.error(\"COPY failed for sql={}, db error={}\", copySql, dbErr.getMessage());\n  }\n  throw e;\n}","preventionTips":["Grant INSERT/COPY privileges to the sink user.","Keep the copy SQL column list in sync with the sink schema.","Reduce batch size and add retries for transient network failures.","Log full causes (InvocationTargetException target) to surface the real DB error."],"tags":["jdbc","copy","sql"],"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"}