Learn R Programming

motherduck (version 0.2.0)

create_schema: Create a Schema in a Database if It Does Not Exist

Description

Ensures that a specified schema exists in the given database. If the connection is to a MotherDuck instance, the function switches to the specified database before creating the schema. It also prints helpful connection and environment information via CLI messages for transparency.

Usage

create_schema(.con, database_name, schema_name)

Value

Invisibly returns NULL. Side effect: creates the schema if necessary and prints CLI messages.

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

database_name

Name of the database to create/use.

schema_name

Name of the schema to create if it does not exist.

Details

  • Uses DBI::dbExecute() with CREATE SCHEMA IF NOT EXISTS to create the schema only when needed.

  • If connected to MotherDuck (determined by validate_md_connection_status()), executes USE <database> before creating the schema.

  • Displays connection/user/database information via internal CLI helpers.

See Also

Other db-manage: alter_table_schema(), copy_tables_to_new_location(), create_database(), create_if_not_exists_share(), create_or_replace_share(), 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()