pentaho/pentaho-kettle · error · KettleDatabaseException
Unable to get next value for sequence :
Error message
Unable to get next value for sequence :
What it means
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.
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
Defensive patterns
Strategy: validation
Validate before calling
// verify sequence exists before use
try (ResultSet rs = database.getConnection().createStatement()
.executeQuery("SELECT sequence_name FROM user_sequences WHERE sequence_name = 'MYSEQ'")) {
if (!rs.next()) throw new IllegalStateException("Sequence MYSEQ missing");
} Try / catch
try {
Long next = database.getNextSequenceValue(null, "MYSEQ", "id");
} catch (KettleDatabaseException e) {
throw new IllegalStateException("Check sequence existence/privileges: " + e.getCause().getMessage());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- AddSequence.Exception.ErrorReadingSequence
- An error occurred executing SQL:
- Couldn't execute SQL:
- Couldn't find any rows because of an error :
- Couldn't find maximum key value from table
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/14b8c46884a5f686.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/core/database/Database.java:1471
public Long getNextSequenceValue( String schemaName, String sequenceName, String keyfield )
throws KettleDatabaseException {
Long retval = null;
String schemaSequence = databaseMeta.getQuotedSchemaTableCombination( schemaName, sequenceName );
try {
if ( pstmtSeq == null ) {
pstmtSeq =
connection.prepareStatement( databaseMeta.getSeqNextvalSQL( databaseMeta.stripCR( schemaSequence ) ) );
}
try ( ResultSet rs = pstmtSeq.executeQuery() ) {
if ( rs.next() ) {
retval = rs.getLong( 1 );
}
}
} catch ( SQLException ex ) {
throw new KettleDatabaseException( "Unable to get next value for sequence : " + schemaSequence, ex );
}
return retval;
}
public void insertRow( String tableName, RowMetaInterface fields, Object[] data ) throws KettleDatabaseException {
insertRow( null, tableName, fields, data );
}
public void insertRow( String schemaName, String tableName, RowMetaInterface fields, Object[] data )
throws KettleDatabaseException {
prepareInsert( fields, schemaName, tableName );
setValuesInsert( fields, data );
insertRow();
closeInsert();
}
public String getInsertStatement( String tableName, RowMetaInterface fields ) {View on GitHub (pinned to f3058517a1)