duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
474 stars 100 forks source link

Pivot not working with prepared statements #310

Open l1xnan opened 4 months ago

l1xnan commented 4 months ago

Executing the pivot statement results in the following error:

let sql = r"
with tbl as (
  select * from read_parquet('test.parquet')
)
PIVOT tbl on a using sum(b)";
let con = duckdb::Connection::open_in_memory().unwrap();
let stmt = con.prepare(sql);
println!("{:?}", stmt);
// Err(DuckDBFailure(Error { code: Unknown, extended_code: 1 }, Some("Invalid Input Error: Cannot prepare multiple statements at once!")))

It may be related to https://github.com/duckdb/duckdb/issues/7720

era127 commented 4 months ago

In my experience with another client api, this was resolved by using the duckdb_query() c api function which will create a materialized result. When using the arrow api it will run with the similar duckdb_query_arrow() which is used with execute_batch(). However execute_batch does not return the result. I think if execute_batch was modified to return the output or a new query() function was add to the Connection then it would work.