Learn R Programming

motherduck (version 0.2.0)

upload_database_to_md: Upload a Local Database to MotherDuck

Description

Creates a new database on MotherDuck (if it does not exist) and copies all objects from an existing local database into it using the COPY FROM DATABASE command.

Usage

upload_database_to_md(.con, from_db_name, to_db_name)

Value

Invisibly returns NULL. Side effect: creates the target database and copies all objects; prints a CLI action report.

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

from_db_name

The local database name to copy from.

to_db_name

The target MotherDuck database to create/overwrite.

Details

  • Runs CREATE DATABASE <to_db_name> if the target database does not exist.

  • Then runs COPY FROM DATABASE <from_db_name> TO <to_db_name> to copy all objects (tables, views, etc.) from the local database.

  • Prints a CLI status report (connection, user, current DB) after completion.

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_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()

Examples

Run this code
if (FALSE) {
con_db <- DBI::dbConnect(duckdb::duckdb(dbdir = tempfile()))
create_table(.con=con_db,.data=mtcars,database_name="memory",schema_name="main",table_name="mtcars")
con_md <- connect_to_motherduck()

upload_database_to_md(con_md, from_db_name = "memory", to_db_name = "analytics")
}

Run the code above in your browser using DataLab