Skip to main content

Loading data into MotherDuck

You can currently use CREATE TABLE AS SELECT to load CSV, Parquet, and JSON files into MotherDuck from either local, Amazon S3, or https sources as shown in the following examples.

# load from local machine into table mytable of the current/active used database
con.sql("CREATE TABLE mytable AS SELECT * FROM '~/filepath.csv'");
# load from an S3 bucket into table mytable of the current/active database
con.sql("CREATE TABLE mytable AS SELECT * FROM 's3://bucket/path/*.parquet'")

If the source data matches the table’s schema exactly you can also use INSERT INTO, as shown in the following example.

# append to table mytable in the currently selected database from S3
con.sql("INSERT INTO mytable SELECT * FROM 's3://bucket/path/*.parquet'")

Copying an entire local DuckDB database To MotherDuck

MotherDuck supports copying your currently opened DuckDB database into a MotherDuck database. The following example copies a local DuckDB database named localdb into a MotherDuck-hosted database named clouddb.

 # open the local db
local_con = duckdb.connect("localdb.ddb")
# load the motherduck extension
local_con.sql("LOAD motherduck")
# The from indicates the file to upload. An empty path indicates the current database
local_con.sql("CREATE DATABASE clouddb FROM CURRENT_DATABASE()")

A local DuckDB database can also be copied by its file path:

local_con = duckdb.connect("md:")
local_con.sql("CREATE DATABASE clouddb FROM 'localdb.ddb'")

See Loading Data into MotherDuck for more detail.