Learn R Programming

motherduck (version 0.2.0)

alter_table_schema: Move Tables from One Schema to Another

Description

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, from_table_names, new_schema)

Value

Invisibly returns a character vector of fully-qualified table names moved. Side effects: creates new_schema if needed and alters table schemas.

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

from_table_names

Character vector of table names to move.

new_schema

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

Details

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

  • For each table in table_names, runs: ALTER TABLE old_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()