> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SqlIterator

> SqlIterator — Kinetica Rust API

[gpudb\_api](https://docs.kinetica.com/content/api/rust/index.md)::<wbr />[sql\_iterator](https://docs.kinetica.com/content/api/rust/sql_iterator/index.md)
[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L159-L177)&#x20;

<pre>`pub struct SqlIterator { /* private fields */ }`</pre>

Iterates over the records an SQL query returns.The first batch is fetched when the iterator is created. Call [`SqlIterator::close`](https://docs.kinetica.com/content/api/rust/sql_iterator/struct.SqlIterator#method.close) when done to drop the paging tables; nothing drops them otherwise.

## Implementations

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L179-L331)
impl [SqlIterator](https://docs.kinetica.com/content/api/rust/sql_iterator/struct.SqlIterator.md)

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L181-L183)
pub async fn [new](#method.new)(db: [Arc](https://doc.rust-lang.org/1.98.1/alloc/sync/struct.Arc.html)\<[Kinetica](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica.md)>, sql: &[str](https://doc.rust-lang.org/1.98.1/std/primitive.str.html)) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<Self, [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Runs `sql`, fetching 10,000 records at a time.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L186-L188)
pub async fn [with\_batch\_size](#method.with_batch_size)( db: [Arc](https://doc.rust-lang.org/1.98.1/alloc/sync/struct.Arc.html)\<[Kinetica](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica.md)>, sql: &[str](https://doc.rust-lang.org/1.98.1/std/primitive.str.html), batch\_size: [i32](https://doc.rust-lang.org/1.98.1/std/primitive.i32.html), ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<Self, [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Runs `sql`, fetching `batch_size` records at a time.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L192-L198)
pub async fn [with\_options](#method.with_options)( db: [Arc](https://doc.rust-lang.org/1.98.1/alloc/sync/struct.Arc.html)\<[Kinetica](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica.md)>, sql: &[str](https://doc.rust-lang.org/1.98.1/std/primitive.str.html), sql\_options: [HashMap](https://doc.rust-lang.org/1.98.1/std/collections/hash/map/struct.HashMap.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html), [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<Self, [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Runs `sql` with the given SQL options, fetching 10,000 records at a time.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L203-L228)
pub async fn [with\_batch\_size\_and\_options](#method.with_batch_size_and_options)( db: [Arc](https://doc.rust-lang.org/1.98.1/alloc/sync/struct.Arc.html)\<[Kinetica](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica.md)>, sql: &[str](https://doc.rust-lang.org/1.98.1/std/primitive.str.html), batch\_size: [i32](https://doc.rust-lang.org/1.98.1/std/primitive.i32.html), sql\_options: [Option](https://doc.rust-lang.org/1.98.1/core/option/enum.Option.html)\<[HashMap](https://doc.rust-lang.org/1.98.1/std/collections/hash/map/struct.HashMap.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html), [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>>, ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<Self, [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Runs `sql` with the given SQL options, fetching `batch_size` records at a time. A `paging_table` option is replaced: the iterator pages through a table of its own, and drops it on close.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L232-L236)
pub fn [set\_sql\_options](#method.set_sql_options)(\&mut self, sql\_options: [Option](https://doc.rust-lang.org/1.98.1/core/option/enum.Option.html)\<[HashMap](https://doc.rust-lang.org/1.98.1/std/collections/hash/map/struct.HashMap.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html), [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>>)

Replaces the SQL options, keeping this iterator’s paging table. A `paging_table` option is replaced, as when the iterator is created.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L239-L241)
pub fn [total\_records](#method.total_records)(\&self) -> [i64](https://doc.rust-lang.org/1.98.1/std/primitive.i64.html)

The number of records the query returns in all.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L244-L246)
pub fn [has\_next](#method.has_next)(\&self) -> [bool](https://doc.rust-lang.org/1.98.1/std/primitive.bool.html)

Whether another record is to come.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L250-L258)
pub async fn [next](#method.next)(\&mut self) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<[GenericRecord](https://docs.kinetica.com/content/api/rust/generic_record/struct.GenericRecord.md), [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

The next record, fetching the next batch when this one is done. Fails when there are no more.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/sql_iterator.rs#L262-L269)
pub async fn [close](#method.close)(\&mut self)

Drops the server-side tables the iteration created. A table that cannot be dropped is logged and skipped.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.