{"record":{"id":"e2a15919e975955f","repo":"pentaho/pentaho-kettle","slug":"error-inserting-row-into-table-tablename-with-values-row","errorCode":null,"errorMessage":"Error inserting row into table [<tableName>] with values: <row>","messagePattern":"Error inserting row into table \\[<tableName>\\] with values: <row>","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/synchronizeaftermerge/SynchronizeAfterMerge.java","lineNumber":446,"sourceCode":"        if ( log.isRowLevel() ) {\n          logRowlevel( \"Written row to error handling : \" + getInputRowMeta().getString( row ) );\n        }\n\n        if ( data.specialErrorHandling && data.supportsSavepoints ) {\n          if ( data.savepoint != null || !data.lookupFailure ) {\n            // do this when savepoint was set, and this is not lookup failure PDI-10878\n            data.db.rollback( data.savepoint );\n            if ( data.releaseSavepoint ) {\n              data.db.releaseSavepoint( data.savepoint );\n            }\n          }\n        }\n        sendToErrorRow = true;\n        errorMessage = dbe.toString();\n      } else {\n        setErrors( getErrors() + 1 );\n        data.db.rollback();\n        throw new KettleException( \"Error inserting row into table [\" + data.realTableName + \"] with values: \"\n          + data.inputRowMeta.getString( row ), dbe );\n      }\n    }\n\n    if ( data.batchMode ) {\n      if ( sendToErrorRow ) {\n        if ( batchProblem ) {\n          data.batchBuffer.add( row );\n          processBatchException( errorMessage, updateCounts, exceptionsList );\n        } else {\n          // Simply add this row to the error row\n          putError( data.inputRowMeta, row, 1L, errorMessage, null, \"SUYNC002\" );\n        }\n      } else {\n        if ( !lineSkipped ) {\n          data.batchBuffer.add( row );\n        }\n","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/synchronizeaftermerge/SynchronizeAfterMerge.java#L428-L464","documentation":"Thrown in lookupValues()'s catch of KettleDatabaseException when the step is not doing row-level error handling: the step rolls back the transaction and rethrows a KettleException naming the target table and the full offending input row, so the developer sees exactly which row and table caused the insert/update/delete to fail.","triggerScenarios":"A KettleDatabaseException (SQLException from executing the DML for the current row) is caught; getStepMeta().isDoingErrorHandling() is false; the code increments errors, rolls back data.db, and throws with data.realTableName and data.inputRowMeta.getString(row).","commonSituations":"Constraint violations (PK/unique/FK/not null), value too long for column, type mismatch between stream field and column, table dropped or renamed, permission denied on the target table.","solutions":["Inspect the wrapped KettleDatabaseException cause (dbe) for the actual SQL error and fix the data/schema issue.","Compare the printed row values against the target table column definitions for type/length mismatches.","Enable error handling on the step to route failing rows to an error stream instead of failing the whole transformation.","Verify the connection user has INSERT/UPDATE/DELETE privileges on the target table."],"exampleFix":"// before: stream field String into NUMBER column\n// after: add a 'Select values' step converting the field to Integer before SynchronizeAfterMerge","handlingStrategy":"try-catch","validationCode":"// Pre-validate row fits target schema\nif (rowValue.length(targetColumn) > columnMaxLen) {\n  throw new ValidationException(\"Value too long for column: \" + targetColumn);\n}","typeGuard":null,"tryCatchPattern":"catch (KettleException e) {\n  if (e.getMessage().startsWith(\"Error inserting row into table\")) {\n    logError(\"Row failed: \" + e.getMessage() + \"; cause: \" + e.getCause());\n  }\n  throw e;\n}","preventionTips":["Match stream field types and lengths to target column definitions.","Grant the connection user required DML privileges.","Enable error handling to capture failing rows instead of rolling back the whole run."],"tags":["database","sql","row-insert","pentaho-kettle"],"backgroundTag":"database-write-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"}