{"record":{"id":"b1307c7b8c30f7f0","repo":"pentaho/pentaho-kettle","slug":"error-while-truncating-table","errorCode":null,"errorMessage":"Error while truncating table ","messagePattern":"Error while truncating table ","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/monet-db-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/monetdbbulkloader/MonetDBBulkLoader.java","lineNumber":394,"sourceCode":"    } catch ( Exception e ) {\n      throw new KettleException( \"Error serializing rows of data to the MonetDB API (MAPI).\", e );\n    }\n\n  }\n\n  public void truncate() throws KettleException {\n    String cmd;\n    String table = data.schemaTable;\n    String truncateStatement = meta.getDatabaseMeta().getTruncateTableStatement( null, table );\n    if ( truncateStatement == null ) {\n      throw new KettleException( \"Truncate table is not supported!\" );\n    }\n    cmd = truncateStatement + \";\";\n\n    try {\n      executeSql( cmd );\n    } catch ( Exception e ) {\n      throw new KettleException( \"Error while truncating table \" + table, e );\n    }\n\n    // try to update the metadata registry\n    util.updateMetadata( meta, -1 );\n    if ( log.isDetailed() ) {\n      logDetailed( \"Successfull: \" + cmd );\n    }\n\n  }\n\n  public void drop() throws KettleException {\n    try {\n      executeSql( \"drop table \" + data.schemaTable );\n    } catch ( Exception e ) {\n      throw new KettleException( \"Error while dropping table \" + data.schemaTable, e );\n    }\n\n  }","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/monet-db-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/monetdbbulkloader/MonetDBBulkLoader.java#L376-L412","documentation":"After obtaining a valid truncate statement, MonetDBBulkLoader.truncate executes it via executeSql(); if execution throws, the error is wrapped in a KettleException naming the table. This means the SQL TRUNCATE itself failed against the MonetDB server, distinct from the dialect not supporting truncate at all.","triggerScenarios":"truncate() runs the TRUNCATE statement and the server rejects it — insufficient privileges, table locked or referenced by constraints, wrong schema/table name, or connection lost mid-statement.","commonSituations":"User lacks TRUNCATE/ALTER privileges; table name/schema mismatch after moving environments; foreign-key-referenced table; transient connection drop during a long transformation.","solutions":["Check the wrapped cause for the server-side SQL error and the exact table name in the message","Grant the connecting user TRUNCATE/ALTER privileges on the target table","Verify the schema-qualified table name matches the target database (schemaTable resolution)","If constraints block truncation, use DELETE instead or handle constraints; check for a server restart mid-run"],"exampleFix":"-- before: privilege denied for etl_user\n-- after (as admin)\nGRANT ALTER ON SCHEMA staging TO etl_user;","handlingStrategy":"retry","validationCode":"// Check privileges and table existence before running\n// As admin on MonetDB:\n// GRANT ALTER ON SCHEMA staging TO etl_user;\n// SELECT * FROM sys.tables WHERE name = 'target_table';","typeGuard":"null","tryCatchPattern":"try {\n  step.run();\n} catch (KettleException e) {\n  if (e.getMessage().startsWith(\"Error while truncating table\")) {\n    logError(\"TRUNCATE failed on \" + e.getMessage() + \": \" + e.getCause().getMessage());\n    // check privileges/table locks, then retry\n  }\n}","preventionTips":["Grant the ETL user TRUNCATE/ALTER privileges on the target schema","Confirm schema-qualified table names after environment migrations","Avoid FK constraints on tables slated for bulk truncate, or clear children first","Add retry/alerting around transformations that begin with a truncate"],"tags":["monetdb","sql","truncate","permissions"],"backgroundTag":"sql-query-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}