{"record":{"id":"14b8c46884a5f686","repo":"pentaho/pentaho-kettle","slug":"unable-to-get-next-value-for-sequence","errorCode":null,"errorMessage":"Unable to get next value for sequence : ","messagePattern":"Unable to get next value for sequence : ","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":1471,"sourceCode":"\n  public Long getNextSequenceValue( String schemaName, String sequenceName, String keyfield )\n    throws KettleDatabaseException {\n    Long retval = null;\n\n    String schemaSequence = databaseMeta.getQuotedSchemaTableCombination( schemaName, sequenceName );\n\n    try {\n      if ( pstmtSeq == null ) {\n        pstmtSeq =\n          connection.prepareStatement( databaseMeta.getSeqNextvalSQL( databaseMeta.stripCR( schemaSequence ) ) );\n      }\n      try ( ResultSet rs = pstmtSeq.executeQuery() ) {\n        if ( rs.next() ) {\n          retval = rs.getLong( 1 );\n        }\n      }\n    } catch ( SQLException ex ) {\n      throw new KettleDatabaseException( \"Unable to get next value for sequence : \" + schemaSequence, ex );\n    }\n\n    return retval;\n  }\n\n  public void insertRow( String tableName, RowMetaInterface fields, Object[] data ) throws KettleDatabaseException {\n    insertRow( null, tableName, fields, data );\n  }\n\n  public void insertRow( String schemaName, String tableName, RowMetaInterface fields, Object[] data )\n    throws KettleDatabaseException {\n    prepareInsert( fields, schemaName, tableName );\n    setValuesInsert( fields, data );\n    insertRow();\n    closeInsert();\n  }\n\n  public String getInsertStatement( String tableName, RowMetaInterface fields ) {","sourceCodeStart":1453,"sourceCodeEnd":1489,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L1453-L1489","documentation":"getNextSequenceValue executes 'SELECT <sequence>.NEXTVAL' (or dialect equivalent) and wraps any SQLException from executeQuery as KettleDatabaseException('Unable to get next value for sequence : ' + schemaSequence). It means the sequence query itself failed against the database.","triggerScenarios":"Calling Database.getNextSequenceValue(schema, sequenceName, keyfield) where the SELECT nextval query throws SQLException: sequence does not exist, no SELECT privilege on the sequence, schema name wrong, or the dialect's sequence SQL is invalid for the target DB.","commonSituations":"Typo in sequence name or schema; sequence created in another schema without synonym; user lacking SELECT on the sequence; moving a transformation between databases where the sequence doesn't exist; using sequence support with a DB that has none configured.","solutions":["Verify the sequence exists: run the nextval SELECT manually with the same user","Check the schema-qualification in the sequence name (schema.sequence)","Grant SELECT on the sequence to the connecting user","Confirm the database type in the connection metadata matches the actual DB so the correct sequence SQL dialect is used","Create the missing sequence in the target database"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify sequence exists before use\ntry (ResultSet rs = database.getConnection().createStatement()\n    .executeQuery(\"SELECT sequence_name FROM user_sequences WHERE sequence_name = 'MYSEQ'\")) {\n  if (!rs.next()) throw new IllegalStateException(\"Sequence MYSEQ missing\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Long next = database.getNextSequenceValue(null, \"MYSEQ\", \"id\");\n} catch (KettleDatabaseException e) {\n  throw new IllegalStateException(\"Check sequence existence/privileges: \" + e.getCause().getMessage());\n}","preventionTips":["Create sequences in all target environments (dev/test/prod)","Grant SELECT on sequences to the connecting user","Qualify sequence names with the correct schema","Match connection DB type to the actual database so dialect SQL is correct"],"tags":["jdbc","sequence","sql"],"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"}