duckdb-rs icon indicating copy to clipboard operation
duckdb-rs copied to clipboard

`FromSql` is not implemented for `Vec<f64>`

Open 0x1997 opened this issue 1 year ago • 4 comments

Is there a way to get a Vec from an array column?

0x1997 avatar Jun 06 '24 15:06 0x1997

I think you can decode it as an Value::List: https://docs.rs/duckdb/latest/duckdb/types/enum.Value.html#variant.List

dvic avatar Nov 05 '24 10:11 dvic

I think you can decode it as an Value::List: https://docs.rs/duckdb/latest/duckdb/types/enum.Value.html#variant.List

Is there a way of doing this without having to iterate over Vec<Value> and convert each element into f64, thereby creating a copy of the vector? We've a situation where the vectors aren't small.

metasim avatar Feb 21 '25 18:02 metasim

Extracting a List result calls from_list(), which just iterates over those values and calls .to_owned() on each one, as I think you're trying to avoid doing.

fn from_list(start: usize, end: usize, idx: usize, values: &ArrayRef) -> Value {
    Value::List(
        (start..end)
            .map(|row| Row::value_ref_internal(row, idx, values).to_owned())
            .collect(),
    )
}

fotonick avatar Mar 04 '25 09:03 fotonick

To put it in more general terms, if I understand how this all works, every result row is a bunch of ValueRefs, which are pointers to memory that duckdb (not duckdb-rs) owns. I would guess that this memory is freed when you finish iterating to the end of a chunk, so you'd better make a copy.

fotonick avatar Mar 04 '25 09:03 fotonick