Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c/driver/postgresql: Support enum type #1483

Closed
Tracked by #1490
paleolimbot opened this issue Jan 23, 2024 · 1 comment · Fixed by #1485
Closed
Tracked by #1490

c/driver/postgresql: Support enum type #1483

paleolimbot opened this issue Jan 23, 2024 · 1 comment · Fixed by #1485

Comments

@paleolimbot
Copy link
Member

It looks like the postgres enum type is not quite supported yet, although there is a workaround:

library(adbcdrivermanager)

db <- adbc_database_init(
  adbcpostgresql::adbcpostgresql(),
  uri = "postgresql://localhost:5432/postgres?user=postgres&password=password") 

db |> 
  execute_adbc("CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')")

db |> 
  adbc_database_release()

# Have to recreate the database after because that's where we cache the types
con <- db <- adbc_database_init(
    adbcpostgresql::adbcpostgresql(),
    uri = "postgresql://localhost:5432/postgres?user=postgres&password=password"
  ) |> 
  adbc_connection_init()

con |> 
  execute_adbc("CREATE TABLE x (a mood)") |> 
  execute_adbc("INSERT INTO x VALUES ('sad')") |> 
  execute_adbc("INSERT INTO x VALUES ('ok')")

# Currently returned as binary (i.e., COPY output)
con |> 
  read_adbc("SELECT * from x") |> 
  as.data.frame() |> 
  dplyr::pull(a) |> 
  unclass() |> 
  vapply(rawToChar, character(1))
#> [1] "sad" "ok"

Created on 2024-01-23 with reprex v2.0.2

@lidavidm
Copy link
Member

It would also be good to have a way to purge the cache or notice that we need to rebuild it, hmm

lidavidm pushed a commit that referenced this issue Jan 31, 2024
Closes #1483.

This was pretty straightforward because the COPY representation is the
same as a string.

I also moved all the COPY examples to the common header (since only a
few were missing and it seemed odd that some of them were in different
spots).

From R:

``` r
library(adbcdrivermanager)

db <- adbc_database_init(
  adbcpostgresql::adbcpostgresql(),
  uri = "postgresql://localhost:5432/postgres?user=postgres&password=password") 

db |> 
  execute_adbc("CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')")

db |> 
  adbc_database_release()

# Have to recreate the database after because that's where we cache the types
con <- db <- adbc_database_init(
    adbcpostgresql::adbcpostgresql(),
    uri = "postgresql://localhost:5432/postgres?user=postgres&password=password"
  ) |> 
  adbc_connection_init()

con |> 
  execute_adbc("CREATE TABLE x (a mood)") |> 
  execute_adbc("INSERT INTO x VALUES ('sad')") |> 
  execute_adbc("INSERT INTO x VALUES ('ok')")

# Returns as string because that's how the driver sees it
con |> 
  read_adbc("SELECT * from x") |> 
  as.data.frame()
#>     a
#> 1 sad
#> 2  ok
```

<sup>Created on 2024-01-23 with [reprex
v2.0.2](https://reprex.tidyverse.org)</sup>
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 a pull request may close this issue.

2 participants