paleolimbot opened a new pull request, #2157:
URL: https://github.com/apache/arrow-adbc/pull/2157
This PR refactors the `BindStream` to use the COPY writer instead of its own
serialization logic. This logic is the same between insertion and binding,
although the API used to send it to the database is slightly different. This is
a helpful consolidation of logic and means that adding type support on the
Arrow or Postgresql side (or fixing bugs in the inference or serialization) is
slightly easier. It also means we can bind parameters that are lists and is a
workaround for inserting into a table with a schema where Postgres knows how to
cast the types (but ADBC might not yet).
``` r
library(adbcdrivermanager)
library(nanoarrow)
con <- adbc_database_init(
adbcpostgresql::adbcpostgresql(),
uri =
"postgresql://localhost:5432/postgres?user=postgres&password=password"
) |>
adbc_connection_init()
# Create an array with a uint32 column
df <- tibble::tibble(uint32_col = 1:5)
array <- df |>
nanoarrow::as_nanoarrow_array(
schema = na_struct(list(uint32_col = na_uint32()))
)
# Create a table with an integer column
con |> execute_adbc("DROP TABLE IF EXISTS adbc_test")
con |> execute_adbc("CREATE TABLE adbc_test (uint32_col int4)")
# This will fail (types not identical)
array |> write_adbc(con, "adbc_test", mode = "append")
#> Error in adbc_statement_execute_query(stmt): INVALID_ARGUMENT: [libpq]
Failed to execute COPY statement: PGRES_FATAL_ERROR ERROR: incorrect binary
data format
#> CONTEXT: COPY adbc_test, line 1, column uint32_col
con |>
execute_adbc("INSERT INTO adbc_test VALUES ($1)", bind = array)
con |>
read_adbc("SELECT * FROM adbc_test") |>
tibble::as_tibble()
#> # A tibble: 5 × 1
#> uint32_col
#> <int>
#> 1 1
#> 2 2
#> 3 3
#> 4 4
#> 5 5
```
<sup>Created on 2024-09-12 with [reprex
v2.1.1](https://reprex.tidyverse.org)</sup>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]