marcboeker / go-duckdb

go-duckdb provides a database/sql driver for the DuckDB database engine.
MIT License
646 stars 97 forks source link

unable to scan a list of strings to `[]string` #264

Closed goenning closed 4 weeks ago

goenning commented 1 month ago
var arr []string
if err := db.QueryRowContext(ctx, "SELECT ['a','b']").Scan(&arr); err != nil {
    return nil, fmt.Errorf("failed to scan array: %w", err)
}

The code above fails with failed to scan array: sql: Scan error on column index 0, name "main.list_value('a', 'b')": unsupported Scan, storing driver.Value type []interface {} into type *[]string

goenning commented 4 weeks ago

For future readers, it turns out you can do this:

var arr duckdb.Composite[[]string]
if err := db.QueryRowContext(ctx, "SELECT ['a','b']").Scan(&arr); err != nil {
    return nil, fmt.Errorf("failed to scan array: %w", err)
}

// arr.Get() is []string