Skip to content

feat(c/driver/postgresql): Add enum type support - #1485

Merged
lidavidm merged 8 commits into
apache:mainfrom
paleolimbot:c-postgres-enum
Jan 31, 2024
Merged

lidavidm merged 8 commits into
apache:mainfrom
paleolimbot:c-postgres-enum

Conversation

@paleolimbot

@paleolimbot paleolimbot commented Jan 23, 2024 •

Copy link
Copy Markdown
Member

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:

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

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

@github-actions github-actions Bot added this to the ADBC Libraries 0.10.0 milestone Jan 23, 2024
@paleolimbot
paleolimbot marked this pull request as ready for review January 31, 2024 14:16
@paleolimbot
paleolimbot requested a review from lidavidm as a code owner January 31, 2024 14:16

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lidavidm
lidavidm merged commit 12ea8b6 into apache:main Jan 31, 2024
@paleolimbot
paleolimbot deleted the c-postgres-enum branch February 6, 2024 21:20
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.

c/driver/postgresql: Support enum type

2 participants