Takes an in-memory tibble (or data frame) and writes it to a database table
using a DBI connection. The function supports both overwrite and
append modes, automatically creates the target database and schema if
they do not exist, and adds audit fields (upload_date, upload_time) to
the written table.
create_table_tbl(
.data,
.con,
database_name,
schema_name,
table_name,
write_type = "overwrite"
)Invisibly returns NULL.
Side effect: writes the tibble to the specified database table.
A tibble or data frame to be written to the database.
A valid DBI connection (DuckDB / MotherDuck).
Name of the database to create/use. If missing, the current database of the connection will be used.
Name of the schema to create/use. If missing, the current schema of the connection will be used.
Name of the table to create or append to.
Write strategy: either "overwrite" (drop/create)
or "append" (insert rows). Defaults to "overwrite".
If the connection is a MotherDuck connection (detected by
validate_md_connection_status()), the function ensures the
database is created and switches to it before creating the schema.
Two audit columns are added to the data before writing:
upload_date (date of run) and upload_time (time and timezone of run).
Uses DBI::Id() to explicitly target the database/schema/table.
write_type = "overwrite" will drop and recreate the table.
write_type = "append" will insert rows into an existing table.