Move Tables from One Schema to Another

Source: R/utils-db.R

Moves one or more tables from an existing schema to a new (target) schema using ⁠ALTER TABLE … SET SCHEMA⁠. If the target schema does not exist, it is created first.

Usage

alter_table_schema(.con, table_names, from_schema, new_schema, silent = FALSE)

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

table_names

Character vector of table names to move.

from_schema

Source schema name (where the tables currently reside).

new_schema

Target schema name (where the tables will be moved).

silent

Logical; if TRUE, suppress CLI output. Default is FALSE.

Value

Invisibly returns NULL. Side effects: creates new_schema if needed and moves tables.

Details

  • Ensures new_schema exists (⁠CREATE SCHEMA IF NOT EXISTS⁠).

  • For each table in table_names, runs: ⁠ALTER TABLE from_schema.table SET SCHEMA new_schema⁠.

  • Table and schema identifiers are safely quoted with glue::glue_sql().

See Also

Other db-manage: copy_tables_to_new_location(), create_database(), create_if_not_exists_share(), create_or_replace_share(), create_schema(), create_table(), delete_and_create_schema(), delete_database(), delete_schema(), delete_table(), describe_share(), drop_share(), list_owned_shares(), list_shared_with_me_shares(), upload_database_to_md()