This is an English translation of a Japanese blog. Some content may not be fully translated.
Snowflake

Data Unload and Upload Using SnowCLI

Prerequisites

  1. CLI Tool Installation:

    • Install SnowSQL
    • Install SnowCLI
  2. Enable sample database

Steps

Delete and recreate working directory

#rm -rf ~/work/temp/upload
mkdir -p ~/work/temp/upload

Create a new database using SnowSQL

snow sql -q 'create or replace database sandbox';

Create a new stage

snow object stage create sandbox.public.my_stage;

Unload data to the stage in the specified format

snow sql -q 'copy into @sandbox.public.my_stage/data.csv from (select * from SNOWFLAKE_SAMPLE_DATA.TPCH_SF1.LINEITEM limit 1000) file_format = (format_name = CSV_FORMAT compression = NONE) SINGLE=TRUE HEADER=TRUE OVERWRITE = TRUE';

Display the list of files in the stage

snow object stage list @sandbox.public.my_stage

Copy files from stage to local directory

cd ~/work/temp/upload
snow object stage copy @sandbox.public.my_stage .

Upload files from local to stage (using SnowCLI)

snow object stage copy data.csv @sandbox.public.my_stage

Upload local files to stage (using SnowSQL)

Login omitted

use database sandbox;
put file://~/work/temp/upload/* @my_stage;

References

Snowflake CLI | Snowflake Documentation

snowflakedb/snowflake-cli: Snowflake CLI is an open-source command-line tool explicitly designed for developer-centric workloads in addition to SQL operations.

Suggest an edit on GitHub