Skip to contents

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)

Arguments

.con

A `DBI` connection (DuckDB / MotherDuck).

new_schema

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

old_schema

Previous schema name (where the tables currently live).

table_names

Character vector of table names to move.

Value

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

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

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