Skip to main content

COPY FROM DATABASE (OVERWRITE)

The COPY FROM DATABASE (OVERWRITE) statement will make the target database contain exactly the same data as the source database using zero-copy cloning, effectively overwriting it.

This command will wait on any ongoing write transactions on the target database to complete, and prevent new ones from starting while it is in progress.

Syntax

COPY FROM DATABASE <source_database> (OVERWRITE [, OPTIONS]) [ TO <target_database> ]

Parameters

  • <source_database>: The name or path of the source database to copy from, can be either a MotherDuck database or a share.
  • <target_database>: The name or path of the target database to create, must be a MotherDuck database that the user owns. If not included it will overwrite the current selected database.
warning

OVERWRITE replaces the target's storage with the source's, so it can't read from a share that carries an include pattern — that would carry the tables the pattern hides. Use COPY FROM DATABASE without OVERWRITE to copy the tables a filtered share exposes.

These additional options can be applied, in addition to OVERWRITE, to specify a specific snapshot of the source database to clone.

NameData TypeValue
SNAPSHOT_TIMETIMESTAMPSelects the newest snapshot created before or at this timestamp
SNAPSHOT_IDUUIDID of snapshot to clone
SNAPSHOT_NAMESTRINGName of snapshot to clone
note

This syntax operates at the metadata level and is therefore unique to MotherDuck.

Zero-copy clone

This command operates purely at the MotherDuck metadata layer, so it is a zero-copy clone. The operation is almost instantaneous and does not duplicate any underlying data.

Transient status compatibility

It is not possible to zero-copy clone data from a transient database to a non-transient database. COPY FROM DATABASE (OVERWRITE) returns an error otherwise, since it would mean violating the database's failsafe guarantees. Because a database's transient status is fixed at creation and can't be changed afterward, you have two options when you want to copy data from a transient database to a non-transient database:

  • Option 1: Recreate the target database so that the transient statuses match. For example, running CREATE OR REPLACE DATABASE will drop the existing target database and create a new zero-copy-clone that inherits the source's transient status:
CREATE OR REPLACE DATABASE dest_db FROM source_db;
  • Option 2: Use the COPY FROM DATABASE command to physically copy the data (i.e. not a zero-copy-clone) across databases with different transient status:
COPY FROM DATABASE source_db TO dest_db;