Write to a Stage and read back through an external table¶
On the MatrixOne server in a single-node test environment, run mkdir -p /tmp/mo-cookbook-stage and check that the service can write there. Alternatively, replace the file:// Stage below with a configured S3/MinIO Stage. Each write creates another file, so the example uses an isolated directory.
CREATE DATABASE cookbook_files;
CREATE STAGE cookbook_stage URL='file:///tmp/mo-cookbook-stage/';
CREATE TABLE cookbook_files.src(id INT, label VARCHAR(20));
INSERT INTO cookbook_files.src VALUES (1,'one'),(2,'two');
CREATE EXTERNAL TABLE cookbook_files.exported(id INT, label VARCHAR(20))
INFILE{'filepath'='stage://cookbook_stage/rows_*.csv',
'format'='csv',
'write_file_pattern'='stage://cookbook_stage/rows_%U.csv'}
FIELDS TERMINATED BY ',';
INSERT INTO cookbook_files.exported SELECT * FROM cookbook_files.src;
SELECT COUNT(*) AS rows_written FROM cookbook_files.exported;
DROP DATABASE cookbook_files;
DROP STAGE cookbook_stage;
rows_written should be 2. Files remain in the underlying Stage storage; check that the directory contains only this experiment before deleting it manually. For a second write, CSV escaping, and JSONLine, see the source round-trip test.