Skip to content

Mastering SnowSQL - The Command-Line Client for Snowflake

Published: at 10:00 AM

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

Supported Operating Systems

Installation

Downloading SnowSQL

  1. Search for SnowSQL:

    • Search Download SnowSQL on Google.
    • Navigate to the official SnowSQL download page or the installation documentation.
  2. Download:

    • Choose the installer for your operating system (e.g., Windows).
    • Download the installation file.

Installing SnowSQL on Windows

  1. Run the Installer:

    • Open the downloaded installation file.
    • Follow the installation wizard by clicking Next through the steps.
    • Complete the installation.
  2. 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

  1. 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();
  1. Combine for Full Account Name:
    • Combine locator, region, and cloud provider.

    • Example: xyz12345.us-east-1.aws

Example Connection

  1. Open Command Prompt:
    • Search for cmd and open the Command Prompt.
  2. Run SnowSQL Command:
snowsql -a xyz12345.us-east-1.aws -u your_username
  1. Enter Password:

Handling Log File Error:

Using Configuration File

Purpose: Store connection information to avoid entering credentials every time.

Configuration:

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.