SnowSQL is a command-line client used to connect to Snowflake, allowing users to execute queries and perform operations directly from their local machine. It supports various DDL and DML operations, data loading/unloading, and integrates with local file systems. This article provides a comprehensive guide on using SnowSQL effectively.
Table of Contents
Open Table of Contents
What is SnowSQL?
Purpose
SnowSQL allows users to connect to Snowflake through the command line to execute queries and operations efficiently.
Features change from time to time with new features being added regularly, it is recommended that you review the documentation for the latest on snowSQL and changes to the CLI client.
Functionality
- Execute SQL queries
- Load and unload data
- Perform DDL (Data Definition Language) operations like creating tables
- Perform DML (Data Manipulation Language) operations like inserting data
Supported Operating Systems
- Windows
- Linux
- MacOS
Installation
Downloading SnowSQL
-
Search for SnowSQL:
- Search Download SnowSQL on Google.
- Navigate to the official SnowSQL download page or the installation documentation.
-
Download:
- Choose the installer for your operating system (e.g., Windows).
- Download the installation file.
Installing SnowSQL on Windows
-
Run the Installer:
- Open the downloaded installation file.
- Follow the installation wizard by clicking Next through the steps.
- Complete the installation.
-
Post-Installation:
- Review the instructions provided for connecting to your Snowflake account.
Connecting to Snowflake
Basic Connection Command
Change
<ACCOUNT_NAME>
&<YOUR_USERNAME>
to the desired information for your account
Syntax:
snowsql -a <ACCOUNT_NAME> -u <YOUR_USERNAME>
Finding Account Identifier
- Locate Account Identifier:
-
In your Snowflake web interface, find the account identifier (account name, region, cloud provider).
-
Example:
xyz12345
-
Alternatively, if you run the below query you can get the account identifier.
-- USE ACCOUNTADMIN ROLE
USE ROLE ACCOUNTADMIN;
-- GET THE ACCOUNT IDENTIFIER FOR A SNOWFLAKE ACCOUNT
SELECT
CURRENT_ACCOUNT();
- Combine for Full Account Name:
-
Combine locator, region, and cloud provider.
-
Example:
xyz12345.us-east-1.aws
-
Example Connection
- Open Command Prompt:
- Search for
cmd
and open the Command Prompt.
- Search for
- Run SnowSQL Command:
snowsql -a xyz12345.us-east-1.aws -u your_username
- Enter Password:
- When prompted, enter your Snowflake account password.
Handling Log File Error:
- If you encounter a log file error, it can often be ignored or resolved by running the Command Prompt as an administrator.
Using Configuration File
Purpose: Store connection information to avoid entering credentials every time.
Configuration:
- Add your connection details to the config file located in the SnowSQL installation directory.
Running Queries
Setting Context
Change
<YOUR_DATABASE>
to the desired database you want to query.
Set Database Context:
USE DATABASE <YOUR_DATABASE>;
With SnowSQL, users can efficiently manage their Snowflake data warehouse from the command line, executing queries, loading and unloading data, and performing essential database operations. By following this guide, you can master SnowSQL and leverage its powerful features to streamline your data workflows.