08 January 2019        Add to Favorites   Report

Install and Configure SnowSQL CLI Client

SnowSQL is the official command line client for connecting to Snowflake to execute SQL queries and perform all DDL and DML operations, including loading data into and unloading data out of database tables. 

First, Download and install the SnowSQL CLI Installer

Once you login to your Snowflake Web user interface, click on the help icon and choose Download. A dialog will open up, as shown above, download the windows version and install the program. Watch the video for step by step instructions

Open the SnowSQL CLI

Now that SnowSQL CLI is installed, open up the RUN prompt or terminal in your pc, and type in "cmd". Once the command line window opens up type in,

snowsql -v

to check the version of snowsql. you should see something similar to 

snowsql v 1.1.71

Now, you can connect to snowsql by using the below command (Just remember to use the proper account (Including region) and username)

snowsql -a your_account_name -u username
You will be prompted to enter the password, and you should be connected now.

Set the DB Context

You need to set the right DB Context every time you log in to SnowSQL, copy paste the below commands,

USE WAREHOUSE TRAINING_WH;
USE DATABASE SNOWFLAKE_SAMPLE_DATA;
USE SCHEMA TPCDS_SF100TCL;

Now you are all set, you can go ahead and type in your SQL queries

Setup the config file for password-less auto login

Typing in the account, username, password, setting DB, schema, warehouse everytime you login to snowsql is a hassle, you can modify the config file to log in automatically.

  • Open the config configuration file in a text editor. The default location of the file is:
    Linux/Mac OS: ~/.snowsql/
    Windows: Your-user-folder.snowsql
  • Navigate to the "Connections" section 

  • Here I have named my connection as Training and gave my user credentials

[connections.Training]
#Can be used in SnowSql as #connect example
accountname = your-account-name
username = your-user-name
password = hidden
dbname=SNOWFLAKE_SAMPLE_DATA
warehousename=TRAINING_WH
schemaname=TPCDS_SF100TCL
  • Save and exit
  • You can now connect to snowsql by using the below command,
snowsql -c Training

How to modify the snowsql display prompt

The SnowSQL prompt dynamically displays the current user, warehouse, database, and schema by default. Dynamic tokens are written as [<token>], e.g. [user] or [warehouse]. When you log in to Snowflake, the prompt displays your user name. When you select a database, schema, or warehouse for the current session using the USE command, the prompt also displays those objects.

You can specify the prompt_format option on the command line or in the [options] section of the configuration file. If you change the option on the command line, the change applies to the current session only. 

!set prompt_format=>> 

To persist the change to future sessions, set the option in the configuration file.

[options]
# If set to false auto-completion will not occur interactive mode.
auto_completion = True
prompt_format=>>

📙 Course Index
◀ Prev: Snowflake overview
▶ Next:


Read great educational content like this and a lot more ! Create my free account now 🎁

Copied