DUMP TABLE

DUMP TABLE exports the data of a table to a destination path, either a local absolute path, a file:// URL, or a stage:// location, with an optional METADATA ONLY mode.

Description

DUMP TABLE writes the contents of a table to a destination for later reload with LOAD TABLE. The destination must be a local absolute path, a file:// URL, or a stage:// path referencing a stage.

With the METADATA ONLY option, only the table schema is written, without row data.

The source table must be a regular base table; temporary tables, external tables, views, sequences, partitioned tables, and tables with auto-increment or foreign-key columns are not supported.

Syntax

DUMP TABLE table_name TO 'path' [METADATA ONLY]

Arguments

Argument

Description

table_name

The table whose data is exported.

path

The destination path. Must be a local absolute path, file:// URL, or stage:// path.

METADATA ONLY

Optional. Export only the schema, without row data.

Examples

DROP DATABASE IF EXISTS dump_table_demo;
CREATE DATABASE dump_table_demo;
USE dump_table_demo;

DROP STAGE IF EXISTS dump_table_stage;
CREATE STAGE dump_table_stage URL = 'file:///tmp/dump-table-demo/';
remove files from stage if exists 'stage://dump_table_stage/full/*';
remove files from stage if exists 'stage://dump_table_stage/full/objects/*';
remove files from stage if exists 'stage://dump_table_stage/metadata/*';

CREATE TABLE src (id INT PRIMARY KEY, value VARCHAR(32));
INSERT INTO src VALUES (1, 'one'), (2, 'two'), (3, 'three');
SELECT mo_ctl('dn', 'flush', 'dump_table_demo.src');

DUMP TABLE src TO 'stage://dump_table_stage/full';
DUMP TABLE src TO 'stage://dump_table_stage/metadata' METADATA ONLY;

DROP STAGE IF EXISTS dump_table_stage;
DROP DATABASE dump_table_demo;

See Also