iterate

abstract fun iterate(fetchSize: Int = 100): IterativeTerminalMethods

Switches the builder to iterative mode, optimal for large datasets.

Transaction Requirement: When fetchSize is greater than 0, this method must be called inside a DataAccess.transaction { } block. Otherwise, a BadStatementException will be thrown. This enforcement prevents the PostgreSQL driver from silently ignoring the fetch size and loading all rows into RAM (which happens when autoCommit is true).

Backdoor (In-memory processing): If you want to use the iterative API for convenience (e.g., deduplication or grouping) on small datasets and you are okay with loading all rows into RAM, set fetchSize to 0. In this case, an active transaction is not required.

dataAccess.transaction {
select("*").from("census_records")
.where("year = @year")
.iterate(fetchSize = 500)
.forEachRowOf<CensusRecord>("year" to 14) { record ->
processCensusEntry(record)
}
}

Return

New builder instance with iterative terminal methods.

Parameters

fetchSize

Number of rows fetched from the database in one batch. Set to 0 to disable cursor-based fetching.

Throws

if fetchSize > 0 and no transaction is active.