tests/testthat/test_dbwritetable.R

test_that("dbWriteTable can write tables with keyword column names", {
  con <- dbConnect(duckdb())
  on.exit(dbDisconnect(con, shutdown = TRUE))

  # NB: name is a reserved word, will need to be escaped as part of writing operation
  sample_data <- data.frame(id = 1:3, name = c("cuthbert", "dibble", "grubb"))
  dbWriteTable(con, "sample_data", sample_data, field.types = c(id = "INTEGER", name = "VARCHAR"))

  # Can read the data we wrote back again
  expect_identical(dbReadTable(con, "sample_data"), sample_data)
})

Try the duckdb package in your browser

Any scripts or data that you put into this service are public.

duckdb documentation built on Nov. 17, 2023, 5:08 p.m.