Skip to content

Conversation

slwu89
Copy link
Contributor

@slwu89 slwu89 commented Mar 17, 2025

Hi DuckDB team!

I am submitting a very small PR to improve value binding to parameters in prepared statements. This is especially important when using the SQL IN operator, for example. I have tried to follow the contribution guide, and included a small test.

Previously we could not bind vectors to parameters, the code in the tests would fail (relevant snippet below). This PR fixes this behavior.

stmt = DBInterface.prepare(con, "FROM test_table WHERE i IN ?;")
results = DBInterface.execute(stmt, ([1,2], ))
df = DataFrame(results)

With the following error:

ERROR: unsupported type for bind
Stacktrace:
 [1] duckdb_bind_internal(stmt::DuckDB.Stmt, i::Int64, val::Vector{Int64})
   @ DuckDB ~/.julia/packages/DuckDB/vI6tj/src/statement.jl:72
 [2] bind_parameters(stmt::DuckDB.Stmt, params::Tuple{Vector{Int64}})
   @ DuckDB ~/.julia/packages/DuckDB/vI6tj/src/statement.jl:78
 [3] execute(stmt::DuckDB.Stmt, params::Tuple{Vector{Int64}})
   @ DuckDB ~/.julia/packages/DuckDB/vI6tj/src/result.jl:709
 [4] execute(stmt::DuckDB.Stmt, params::Tuple{Vector{Int64}})
   @ DuckDB ~/.julia/packages/DuckDB/vI6tj/src/result.jl:872
 [5] top-level scope
   @ ~/some-path-removed-for-security

Thanks to the new support for List types provided in #16512 the same code now returns:

julia> df = DataFrame(results)
4×2 DataFrame
 Row │ i      j       
     │ Int32  Float64 
─────┼────────────────
   11      3.5
   22      0.5
   31      1.0
   42      2.0

@duckdb-draftbot duckdb-draftbot marked this pull request as draft March 17, 2025 23:07
@slwu89 slwu89 marked this pull request as ready for review March 17, 2025 23:08
@duckdb-draftbot duckdb-draftbot marked this pull request as draft March 17, 2025 23:21
@slwu89 slwu89 marked this pull request as ready for review March 17, 2025 23:44
@Mytherin Mytherin merged commit 1295db8 into duckdb:main Mar 18, 2025
8 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

@slwu89 slwu89 deleted the julia-bind branch March 18, 2025 14:05
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 15, 2025
Make CSV Parser strict_mode=True fail on a mix of new line delimiters. (duckdb/duckdb#15959)
[Julia] support binding for vectors (duckdb/duckdb#16701)
JSON Reader: make read_position atomic so this can be read by the progress bar while processing the JSON file (duckdb/duckdb#16692)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 15, 2025
Make CSV Parser strict_mode=True fail on a mix of new line delimiters. (duckdb/duckdb#15959)
[Julia] support binding for vectors (duckdb/duckdb#16701)
JSON Reader: make read_position atomic so this can be read by the progress bar while processing the JSON file (duckdb/duckdb#16692)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 16, 2025
Make CSV Parser strict_mode=True fail on a mix of new line delimiters. (duckdb/duckdb#15959)
[Julia] support binding for vectors (duckdb/duckdb#16701)
JSON Reader: make read_position atomic so this can be read by the progress bar while processing the JSON file (duckdb/duckdb#16692)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 16, 2025
Make CSV Parser strict_mode=True fail on a mix of new line delimiters. (duckdb/duckdb#15959)
[Julia] support binding for vectors (duckdb/duckdb#16701)
JSON Reader: make read_position atomic so this can be read by the progress bar while processing the JSON file (duckdb/duckdb#16692)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 17, 2025
Make CSV Parser strict_mode=True fail on a mix of new line delimiters. (duckdb/duckdb#15959)
[Julia] support binding for vectors (duckdb/duckdb#16701)
JSON Reader: make read_position atomic so this can be read by the progress bar while processing the JSON file (duckdb/duckdb#16692)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants