{"record":{"id":"57b996409c78ed29","repo":"pentaho/pentaho-kettle","slug":"no-fields-in-row-can-t-insert","errorCode":null,"errorMessage":"No fields in row, can't insert!","messagePattern":"No fields in row, can't insert!","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":1228,"sourceCode":"   * @param tableName The name of the table in which we want to insert rows\n   * @throws KettleDatabaseException if something went wrong.\n   */\n  public void prepareInsert( RowMetaInterface rowMeta, String tableName ) throws KettleDatabaseException {\n    prepareInsert( rowMeta, null, tableName );\n  }\n\n  /**\n   * Prepare inserting values into a table, using the fields & values in a Row\n   *\n   * @param rowMeta    The metadata row to determine which values need to be inserted\n   * @param schemaName The name of the schema in which we want to insert rows\n   * @param tableName  The name of the table in which we want to insert rows\n   * @throws KettleDatabaseException if something went wrong.\n   */\n  public void prepareInsert( RowMetaInterface rowMeta, String schemaName, String tableName )\n    throws KettleDatabaseException {\n    if ( rowMeta.size() == 0 ) {\n      throw new KettleDatabaseException( \"No fields in row, can't insert!\" );\n    }\n\n    String ins = getInsertStatement( schemaName, tableName, rowMeta );\n\n    if ( log.isDetailed() ) {\n      log.logDetailed( \"Preparing statement: \" + Const.CR + ins );\n    }\n    prepStatementInsert = prepareSQL( ins );\n  }\n\n  /**\n   * Prepare a statement to be executed on the database. (does not return generated keys)\n   *\n   * @param sql The SQL to be prepared\n   * @return The PreparedStatement object.\n   * @throws KettleDatabaseException\n   */\n  public PreparedStatement prepareSQL( String sql ) throws KettleDatabaseException {","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L1210-L1246","documentation":"KettleDatabaseException thrown by Database.prepareInsert() when the supplied RowMetaInterface has zero fields, meaning there is no column list to build an INSERT statement from. This is a programming/data error caught before any JDBC work happens — the generated INSERT would be invalid SQL.","triggerScenarios":"Calling prepareInsert(rowMeta, schemaName, tableName) with an empty RowMeta (rowMeta.size() == 0) — usually a step upstream produced no fields or fields were removed from the row layout.","commonSituations":"Table output/insert steps receiving empty rows due to misconfigured field mapping, a select step dropping all columns, or dynamically built RowMeta that was never populated.","solutions":["Ensure the RowMeta passed to prepareInsert contains at least one field","Check upstream steps/field mappings so fields are not accidentally removed or filtered","If fields are determined at runtime, validate rowMeta.size() > 0 before calling prepareInsert"],"exampleFix":"// before\ndatabase.prepareInsert( rowMeta, schema, table );\n// after\nif ( rowMeta.size() == 0 ) {\n  throw new KettleException( \"No fields to insert into \" + table );\n}\ndatabase.prepareInsert( rowMeta, schema, table );","handlingStrategy":"validation","validationCode":"if ( rowMeta == null || rowMeta.size() == 0 ) {\n  throw new KettleException( \"RowMeta has no fields; cannot prepare insert into \" + tableName );\n}","typeGuard":"boolean hasFields( RowMetaInterface row ) {\n  return row != null && row.size() > 0;\n}","tryCatchPattern":null,"preventionTips":["Validate row layout before insert/prepareInsert calls","Check upstream step field mappings so columns are not dropped","Log rowMeta.getFieldNames() during development to confirm the expected columns"],"tags":["database","insert","validation","rowmeta"],"backgroundTag":"empty-required-field","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"}