Snowflake CLI
Introduction
Section titled “Introduction”Snowflake CLI is a command-line interface (CLI) for Snowflake. You can use Snowflake CLI to interact with the Snowflake emulator. Snowflake CLI provides a set of commands to manage and interact with Snowflake accounts, databases, warehouses, and more.
You can connect Snowflake CLI to the Snowflake emulator using a connection profile. A connection profile is a set of parameters that define the connection to a Snowflake account. You can create, list, and test connection profiles using Snowflake CLI.
Installation
Section titled “Installation”You can install Snowflake CLI using the following methods:
pip install snowflake-cli-labssnow --help
brew tap Snowflake-Labs/snowflake-clibrew install snowclisnow --help
Configuring Snowflake CLI
Section titled “Configuring Snowflake CLI”In this guide, you will learn how to configure Snowflake CLI to interact with the Snowflake emulator using a localstack
connection profile.
Create a connection profile
Section titled “Create a connection profile”To configure Snowflake CLI to interact with the Snowflake emulator, create a connection profile using the following command:
snow connection add \ --connection-name localstack \ --user test \ --password test \ --account test \ --host snowflake.localhost.localstack.cloud
You might be prompted to enter more optional parameters, such as the connection port, database name, warehouse name, authentication method, and more. These are however optional and can be skipped.
After a successful configuration, you can the localstack
connection profile is ready to use.
List your connection profiles
Section titled “List your connection profiles”To list all the connection profiles configured in Snowflake CLI, execute the following command:
snow connection list
The output should be:
+-----------------------------------------------------------------------------------+| connection_name | parameters ||-----------------+-----------------------------------------------------------------|| localstack | {'account': 'test', 'user': 'test', 'password': '****', || | 'host': 'snowflake.localhost.localstack.cloud'} |+-----------------------------------------------------------------------------------+
Test the connection
Section titled “Test the connection”To test the connection to the Snowflake emulator, execute the following command:
snow connection test --connection localstack
The output should be:
+--------------------------------------------------------+| key | value ||-----------------+--------------------------------------|| Connection name | localstack || Status | OK || Host | snowflake.localhost.localstack.cloud || Account | test || User | test |+--------------------------------------------------------+
Run a query using the connection profile
Section titled “Run a query using the connection profile”To run a query using the connection profile, execute the following command:
snow sql --query "CREATE DATABASE mytestdb;" --connection localstack
You can see all the databases in your Snowflake emulator using the following command:
snow sql --query "SHOW DATABASES;" --connection localstack
You can create a schema using the following commands:
snow sql --query "CREATE SCHEMA mytestdb.mytestschema;" --connection localstack