Skip to contents

Copies one or more tables to a new location (database/schema) by creating new tables via `CREATE TABLE ... AS SELECT * FROM ...`. If connected to MotherDuck, the target database is created if missing, and the target schema is created if missing on any connection.

Usage

copy_tables_to_new_location(
  .con,
  from_table_names,
  to_database_name,
  to_schema_name
)

Arguments

.con

A `DBI` connection (DuckDB / MotherDuck).

from_table_names

A tibble/data frame listing source tables, with columns `database_name`, `schema_name`, and `table_name`.

to_database_name

Target database name.

to_schema_name

Target schema name.

Value

Invisibly returns a character vector of fully-qualified destination table names that were created. Side effect: creates target DB/schema if needed and writes new tables.

Details

- Input `from_table_names` must contain columns: `database_name`, `schema_name`, and `table_name`. - For each source table, the function issues: `CREATE TABLE <to_db>.<to_schema>.<table> AS SELECT * FROM <src_db>.<src_schema>.<table>`. - On local DuckDB (non-MotherDuck), the target database name is ignored and defaults to the current database of the connection.

See also

[DBI::dbExecute()], [DBI::Id()]