duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
511 stars 113 forks source link

Listing tables in rust never iterates #267

Closed mgrazianoc closed 9 months ago

mgrazianoc commented 9 months ago

The following code tries to get the current tables available in the database, before deciding whether it should download it from elsewhere.

let mut table_exists = false;
let table_name = String::from("test");
let mut stmt = conn.prepare("SHOW TABLES;")?;
let _ = stmt.query_map([], |row| {
    let t: String = row.get("name")?;
    if t == table_name {
        table_exists = true;
    }
    Ok(())
})?;

But, the query_map call never iterates, the system continues to download the table, and it raises that the table test already exists.

I've tested these behaviors on duckdb 0.9.0, 0.9.2 and 0.10.0.

era127 commented 9 months ago

I think the iterator is lazy, try to consume the result of iterator with collect.

mgrazianoc commented 9 months ago

Yep, it was that, thanks