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,
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 usernameYou 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/
Navigate to the "Connections" section
Here I have named my connection as Training and gave my user credentials
#Can be used in SnowSql as #connect example
accountname = your-account-name
username = your-user-name
password = hidden
- 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.
To persist the change to future sessions, set the option in the configuration file.
# If set to false auto-completion will not occur interactive mode.
auto_completion = True