{"record":{"id":"3c00e3e61657849f","repo":"apache/seatunnel","slug":"failed-truncate-table-s-in-catalog-s","errorCode":null,"errorMessage":"Failed truncate table %s in catalog %s","messagePattern":"Failed truncate table (.+?) in catalog (.+?)","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java","lineNumber":695,"sourceCode":"    // If sql is DDL, the execute() method always returns false, so the return value\n    // should not be used to determine whether changes were made in database.\n    protected boolean executeInternal(String url, String sql) throws SQLException {\n        LOG.info(\"Execute sql : {}\", sql);\n        try (PreparedStatement ps = getConnection(url).prepareStatement(sql)) {\n            return ps.execute();\n        }\n    }\n\n    public CatalogTable getTable(String sqlQuery) throws SQLException {\n        Connection defaultConnection = getConnection(defaultUrl);\n        return CatalogUtils.getCatalogTable(defaultConnection, sqlQuery);\n    }\n\n    protected void truncateTableInternal(TablePath tablePath) throws CatalogException {\n        try {\n            executeInternal(defaultUrl, getTruncateTableSql(tablePath));\n        } catch (Exception e) {\n            throw new CatalogException(\n                    String.format(\n                            \"Failed truncate table %s in catalog %s\",\n                            tablePath.getFullName(), this.catalogName),\n                    e);\n        }\n    }\n\n    protected String getTruncateTableSql(TablePath tablePath) {\n        throw new UnsupportedOperationException();\n    }\n\n    protected String getExistDataSql(TablePath tablePath) {\n        throw new UnsupportedOperationException();\n    }\n\n    public void executeSql(TablePath tablePath, String sql) {\n        String dbUrl = getUrlFromDatabaseName(tablePath.getDatabaseName());\n        Connection connection = getConnection(dbUrl);","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/AbstractJdbcCatalog.java#L677-L713","documentation":"CatalogException thrown by truncateTableInternal when executing the TRUNCATE TABLE statement fails with any exception. The message names the full table path and catalog; the cause holds the driver-level error.","triggerScenarios":"catalog.truncateTable(tablePath, ignoreIfNotExists=false) on an existing table where executeInternal(defaultUrl, getTruncateTableSql(tablePath)) throws: TRUNCATE privilege missing, FK constraints referencing the table, table locked by active transactions, or unsupported truncate syntax.","commonSituations":"User has DML but not DDL/TRUNCATE rights; MySQL InnoDB table referenced by foreign keys (TRUNCATE fails where DELETE works); row locks from long-running readers/writers; dialect where getTruncateTableSql produces invalid SQL.","solutions":["Inspect the wrapped cause for the driver-level reason.","Grant TRUNCATE/ALTER privileges to the catalog user.","Remove or disable foreign keys referencing the table, or use DELETE FROM instead.","Ensure no long-running transactions hold locks on the table.","Verify getTruncateTableSql output against your DBMS syntax manually."],"exampleFix":"// before\ncatalog.truncateTable(TablePath.of(\"db\", \"orders\"), false); // FK referenced\n// after\ntry (Connection conn = DriverManager.getConnection(url, user, pass);\n     Statement st = conn.createStatement()) {\n    st.execute(\"SET FOREIGN_KEY_CHECKS=0\");\n    st.execute(\"TRUNCATE TABLE db.orders\");\n    st.execute(\"SET FOREIGN_KEY_CHECKS=1\");\n}","handlingStrategy":"try-catch","validationCode":"if (!catalog.tableExists(tablePath)) return; // nothing to truncate","typeGuard":null,"tryCatchPattern":"try { catalog.truncateTable(path, false); } catch (CatalogException e) { LOG.error(\"Truncate {} failed: {}\", path.getFullName(), e.getCause(), e); }","preventionTips":["Ensure the user has TRUNCATE/ALTER privileges","Check for FK references before truncating","Avoid truncating tables under active transactions","Verify getTruncateTableSql output for your DBMS dialect"],"tags":["jdbc","catalog","sql","truncate"],"backgroundTag":"database-write-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"}