{"record":{"id":"5d3d56ba7b85038a","repo":"pentaho/pentaho-kettle","slug":"truncate-table-not-supported-by-databasemeta","errorCode":null,"errorMessage":"Truncate table not supported by \" + databaseMeta.getDatabaseInterface().getPluginName()","messagePattern":"Truncate table not supported by \" \\+ databaseMeta\\.getDatabaseInterface\\(\\)\\.getPluginName\\(\\)","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":3575,"sourceCode":"        }\n      }\n    }\n\n    if ( modify.size() > 0 ) {\n      for ( int i = 0; i < modify.size(); i++ ) {\n        ValueMetaInterface v = modify.getValueMeta( i );\n        retval.append( databaseMeta.getModifyColumnStatement( tableName, v, tk, useAutoinc, pk, true ) );\n      }\n    }\n\n    return retval.toString();\n  }\n\n  public void truncateTable( String tablename ) throws KettleDatabaseException {\n    if ( Utils.isEmpty( connectionGroup ) ) {\n      String truncateStatement = databaseMeta.getTruncateTableStatement( null, tablename );\n      if ( truncateStatement == null ) {\n        throw new KettleDatabaseException( \"Truncate table not supported by \"\n          + databaseMeta.getDatabaseInterface().getPluginName() );\n      }\n      execStatement( truncateStatement );\n    } else {\n      execStatement( \"DELETE FROM \" + databaseMeta.quoteField( tablename ) );\n    }\n  }\n\n  public void truncateTable( String schema, String tablename ) throws KettleDatabaseException {\n    if ( Utils.isEmpty( connectionGroup ) && !databaseMeta.getPluginId().equalsIgnoreCase(\n      \"MySQL\" ) ) { // this is a hack to fix a know issue on MySQL issue name on Pentaho side BISERVER-14546\n      String truncateStatement = databaseMeta.getTruncateTableStatement( schema, tablename );\n      if ( truncateStatement == null ) {\n        throw new KettleDatabaseException( \"Truncate table not supported by \"\n          + databaseMeta.getDatabaseInterface().getPluginName() );\n      }\n      execStatement( truncateStatement );\n    } else {","sourceCodeStart":3557,"sourceCodeEnd":3593,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L3557-L3593","documentation":"Database.truncateTable(String) issues a TRUNCATE TABLE statement via databaseMeta.getTruncateTableStatement(null, tablename). When the active database plugin does not define a truncate statement, the method returns null and Kettle throws this KettleDatabaseException instead of silently falling back. It signals that the connected database dialect has no TRUNCATE implementation in the repository's database plugins.","triggerScenarios":"Calling db.truncateTable( tablename ) (single-arg overload) while (a) no connectionGroup is set, and (b) databaseMeta.getTruncateTableStatement(null, tablename) returns null — i.e. the current database plugin does not implement getTruncateTableStatement. Note that inside a connection group (batch mode) this exception is never thrown; a DELETE FROM is used instead.","commonSituations":"Using a custom or less-common database plugin (SAP HANA, Ingres, generic JDBC, MonetDB, etc.) that lacks a truncate statement in its DatabaseMeta; truncating tables during transformation steps against non-standard dialects; running the same job that works on PostgreSQL/Oracle against an exotic target database.","solutions":["Implement getTruncateTableStatement() in the database plugin's DatabaseMeta class (return \"TRUNCATE TABLE \" + quoted table name) so the plugin supports truncation","Use the connection-group path instead: group connections so the code falls back to execStatement(\"DELETE FROM table\"), or execute the DELETE explicitly","Run the operation against a database plugin known to support truncation, or check support first with databaseMeta.getTruncateTableStatement(null, tablename) != null","Upgrade Pentaho/Kettle — newer versions added truncate statements for more dialects"],"exampleFix":"// before\ndatabase.truncateTable( \"staging_log\" ); // throws for plugins without truncate support\n// after\nString stmt = database.getDatabaseMeta().getTruncateTableStatement( null, \"staging_log\" );\nif ( stmt != null ) {\n  database.execStatement( stmt );\n} else {\n  database.execStatement( \"DELETE FROM \" + database.getDatabaseMeta().quoteField( \"staging_log\" ) );\n}","handlingStrategy":"validation","validationCode":"String stmt = databaseMeta.getTruncateTableStatement( null, tablename );\nif ( stmt == null ) {\n  // dialect lacks truncate — fall back or fail fast before calling truncateTable\n  database.execStatement( \"DELETE FROM \" + databaseMeta.quoteField( tablename ) );\n} else {\n  database.truncateTable( tablename );\n}","typeGuard":"boolean supportsTruncate( DatabaseMeta meta, String table ) {\n  return meta != null && meta.getTruncateTableStatement( null, table ) != null;\n}","tryCatchPattern":"try {\n  database.truncateTable( tablename );\n} catch ( KettleDatabaseException e ) {\n  if ( e.getMessage() != null && e.getMessage().startsWith( \"Truncate table not supported\" ) ) {\n    database.execStatement( \"DELETE FROM \" + databaseMeta.quoteField( tablename ) );\n  } else {\n    throw e;\n  }\n}","preventionTips":["Check getTruncateTableStatement(...) for null before truncating on non-mainstream dialects","Keep database plugins/driver versions current — newer releases add truncate support for more dialects","Use a DELETE fallback for dialects known to lack TRUNCATE","Test table-maintenance steps against every target database type in your environments"],"tags":["database","jdbc","unsupported-operation","dialect"],"backgroundTag":"unsupported-operation","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"}