{"record":{"id":"66f5f0c8574d0dad","repo":"pentaho/pentaho-kettle","slug":"addsequence-exception-errorreadingsequence","errorCode":null,"errorMessage":"AddSequence.Exception.ErrorReadingSequence","messagePattern":"AddSequence\\.Exception\\.ErrorReadingSequence","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"critical","filePath":"plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java","lineNumber":74,"sourceCode":"      synchronized ( data.counter ) {\n        long prev = data.counter.getCounter();\n\n        long nval = prev + data.increment;\n        if ( data.increment > 0 && data.maximum > data.start && nval > data.maximum ) {\n          nval = data.start;\n        }\n        if ( data.increment < 0 && data.maximum < data.start && nval < data.maximum ) {\n          nval = data.start;\n        }\n        data.counter.setCounter( nval );\n\n        next = prev;\n      }\n    } else if ( meta.isDatabaseUsed() ) {\n      try {\n        next = data.getDb().getNextSequenceValue( data.realSchemaName, data.realSequenceName, meta.getValuename() );\n      } catch ( KettleDatabaseException dbe ) {\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"AddSequence.Exception.ErrorReadingSequence\", data.realSequenceName ), dbe );\n      }\n    } else {\n      // This should never happen, but if it does, don't continue!!!\n      throw new KettleStepException( BaseMessages.getString( PKG, \"AddSequence.Exception.NoSpecifiedMethod\" ) );\n    }\n\n    if ( next != null ) {\n      Object[] outputRowData = inputRowData;\n      if ( inputRowData.length < inputRowMeta.size() + 1 ) {\n        outputRowData = RowDataUtil.resizeArray( inputRowData, inputRowMeta.size() + 1 );\n      }\n      outputRowData[inputRowMeta.size()] = next;\n      return outputRowData;\n    } else {\n      throw new KettleStepException( BaseMessages.getString(\n        PKG, \"AddSequence.Exception.CouldNotFindNextValueForSequence\" )\n        + meta.getValuename() );","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/addsequence/AddSequence.java#L56-L92","documentation":"AddSequence.addSequence throws KettleStepException with this message when getNextSequenceValue on the configured database fails while fetching the next value of a DB sequence. The sequence name is embedded in the message; the KettleDatabaseException is the cause.","triggerScenarios":"Executing the AddSequence step with isDatabaseUsed() true and data.getDb().getNextSequenceValue(realSchemaName, realSequenceName, valuename) throwing — wrong schema/sequence name, sequence dropped, or insufficient SELECT privilege on the sequence.","commonSituations":"Sequence name typo or case-sensitivity on Oracle/Postgres, missing schema qualifier, sequence exists in dev but not prod, DB user lacking sequence SELECT grant, connection dropped mid-run.","solutions":["Verify the sequence name and schema in the step dialog exist on the target DB (SELECT from user_sequences / pg_sequences).","Grant SELECT on the sequence to the connection's DB user.","Check the wrapped KettleDatabaseException for SQL errors (ORA-02289 sequence does not exist is the usual one).","Confirm the step's connection points at the intended environment's database."],"exampleFix":"// before\nnext = data.getDb().getNextSequenceValue( data.realSchemaName, data.realSequenceName, meta.getValuename() );\n// after (environment variable substitution keeps env-specific sequence names)\nString seq = environmentSubstitute( meta.getSequenceName() );\nnext = data.getDb().getNextSequenceValue( environmentSubstitute( meta.getSchemaName() ), seq, meta.getValuename() );","handlingStrategy":"try-catch","validationCode":"// verify the sequence exists and is readable before running the transformation\nSELECT sequence_name FROM all_sequences WHERE sequence_owner = ? AND sequence_name = UPPER(?); -- Oracle\n-- or Postgres: SELECT 1 FROM pg_sequences WHERE schemaname = ? AND sequencename = ?;","typeGuard":null,"tryCatchPattern":"try { /* run transformation with AddSequence */ } catch ( KettleStepException e ) { if ( e.getMessage().contains( \"AddSequence.Exception.ErrorReadingSequence\" ) ) { logError( \"Sequence \" + seqName + \" missing or inaccessible: \" + e.getCause(), e ); } }","preventionTips":["Create sequences in all environments via migration scripts (Flyway/Liquibase).","Use exact-case sequence names on Oracle/Postgres and qualify with schema.","Grant SELECT on sequences to the PDI connection user.","Point the step's connection at the correct environment database."],"tags":["database","sequence","sql","runtime","step-execution"],"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"}