Upsert into a DuckLake table using MERGE INTO
Usage
db_upsert(
data,
schema = "main",
table,
by,
strict = TRUE,
update_cols = NULL,
commit_author = NULL,
commit_message = NULL
)Arguments
- data
data.frame / tibble
- schema
Schema name (default "main")
- table
Table name
- by
Character vector of key columns used to match rows
- strict
If TRUE (default), refuse to upsert if duplicates exist in
datafor thebykey.- update_cols
Controls which columns to update on match:
NULL (default): update all columns
character(0): insert-only (no updates on match)
character vector: update only specified columns
Optional DuckLake commit author
- commit_message
Optional DuckLake commit message
Examples
if (FALSE) { # \dontrun{
# Basic upsert by id
db_upsert(my_data, table = "products", by = "product_id")
# Composite key
db_upsert(my_data, table = "sales", by = c("region", "date"))
# Update only specific columns
db_upsert(my_data, table = "products", by = "product_id",
update_cols = c("price", "updated_at"))
# Insert-only (no updates)
db_upsert(my_data, table = "events", by = "event_id",
update_cols = character(0))
# With commit metadata
db_upsert(my_data, table = "products", by = "product_id",
commit_author = "jsmith",
commit_message = "Price update batch")
} # }