0% found this document useful (0 votes)
251 views

Install and Configure SnowSQL

SnowSQL is the command line interface for Snowflake. It can be installed by downloading the appropriate version for your system from the Snowflake web interface. Configuration of SnowSQL connections and settings is done through a config file located at ~/.snowsql/config, which allows persisting connection details and preferences between sessions. SnowSQL provides commands and options to connect to Snowflake, execute SQL statements and files, view results, and manage sessions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
251 views

Install and Configure SnowSQL

SnowSQL is the command line interface for Snowflake. It can be installed by downloading the appropriate version for your system from the Snowflake web interface. Configuration of SnowSQL connections and settings is done through a config file located at ~/.snowsql/config, which allows persisting connection details and preferences between sessions. SnowSQL provides commands and options to connect to Snowflake, execute SQL statements and files, view results, and manage sessions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Install and configure SnowSQL

SnowSQL is the command-line interface for accessing


your Snowflake instance.

The following is a quick "how to" guide for setting it up.

Installation

After logging into your Snowflake web interface, the SnowSQL installer is
available via Help -> Download:

You'll need to select the appropriate version for your machine:


..and install it:
To verify installation, simply open a terminal window and run snowsql. If
installed properly, you will receive a list of connection and option flags:
$ snowsql
Usage: snowsql [OPTIONS]
Options:
-a, --accountname TEXT Name assigned to your Snowflake account. If
you are not on us-west-2 or AWS deployement,
append the region and platform to the end,
e.g., <account>.<region> or
<account>.<region>.<platform>Honors
$SNOWSQL_ACCOUNT.
-u, --username TEXT Username to connect to Snowflake. Honors
$SNOWSQL_USER.
-d, --dbname TEXT Database to use. Honors $SNOWSQL_DATABASE.
-s, --schemaname TEXT Schema in the database to use. Honors
$SNOWSQL_SCHEMA.
-r, --rolename TEXT Role name to use. Honors $SNOWSQL_ROLE.
-w, --warehouse TEXT Warehouse to use. Honors $SNOWSQL_WAREHOUSE.
-h, --host TEXT Host address for the connection. Honors
$SNOWSQL_HOST.
-p, --port INTEGER Port number for the connection. Honors
$SNOWSQL_PORT.
--region TEXT (DEPRECATED) Append the region or any sub
domains before snowflakecomputing.com to the
end of accountname parameter after a dot.
e.g., accountname=<account>.<region>
-m, --mfa-passcode TEXT Token to use for multi-factor authentication
(MFA)
--mfa-passcode-in-password Appends the MFA passcode to the end of the
password.
--abort-detached-query Aborts a query if the connection between the
client and server is lost. By default, it
won't abort even if the connection is lost.
--probe-connection Test connectivity to Snowflake. This option
is mainly used to print out the TLS/SSL
certificate chain.
--proxy-host TEXT (DEPRECATED. Use HTTPS_PROXY and HTTP_PROXY
environment variables.) Proxy server
hostname. Honors $SNOWSQL_PROXY_HOST.
--proxy-port INTEGER (DEPRECATED. Use HTTPS_PROXY and HTTP_PROXY
environment variables.) Proxy server port
number. Honors $SNOWSQL_PROXY_PORT.
--proxy-user TEXT (DEPRECATED. Use HTTPS_PROXY and HTTP_PROXY
environment variables.) Proxy server
username. Honors $SNOWSQL_PROXY_USER. Set
$SNOWSQL_PROXY_PWD for the proxy server
password.
--authenticator TEXT Authenticator: 'snowflake',
'externalbrowser' (to use any IdP and a web
browser), or
https://<your_okta_account_name>.okta.com
(to use Okta natively).
-v, --version Shows the current SnowSQL version, or uses a
specific version if provided as a value.
--noup Disables auto-upgrade for this run. If no
version is specified for -v, the latest
version in ~/.snowsql/ is used.
-D, --variable TEXT Sets a variable to be referred by &<var>. -D
tablename=CENUSTRACKONE or --variable
db_key=$DB_KEY
-o, --option TEXT Set SnowSQL options. See the options
reference in the Snowflake documentation.
-f, --filename PATH File to execute.
-q, --query TEXT Query to execute.
--config PATH Path and name of the SnowSQL configuration
file. By default, ~/.snowsql/config.
-P, --prompt Forces a password prompt. By default,
$SNOWSQL_PWD is used to set the password.
-M, --mfa-prompt Forces a prompt for the second token for
MFA.
-c, --connection TEXT Named set of connection parameters to use.
--single-transaction Connects with autocommit disabled. Wraps
BEGIN/COMMIT around statements to execute
them as a single transaction, ensuring all
commands complete successfully or no change
is applied.
--private-key-path PATH Path to private key file in PEM format used
for key pair authentication. Private key
file is required to be encrypted and
passphrase is required to be specified in
environment variable
$SNOWSQL_PRIVATE_KEY_PASSPHRASE
-U, --upgrade Force upgrade of SnowSQL to the latest
version.
-K, --client-session-keep-alive
Keep the session active indefinitely, even
if there is no activity from the user..
--disable-request-pooling Disable request pooling. This can help speed
up connection failover
-?, --help Show this message and exit.

Configuration

As indicated above, SnowSQL has a host of connection params and settings,


and allows variable declaration and substitution. You won't need to be familiar
with all the options to hit the ground running, but I definitely recommend
leveraging ~/.snowsql/config to persist your connection details and personal
preferences.

Create ~/.snowsql/config
$ touch ~/.snowsql/config

Add your connection details to the [connections] section.

The first few lines of your ~/.snowsql/config file should look like the following:
[connections]
accountname = YOUR_ACCOUNT_NAME
username = YOUR_USERNAME
password = YOUR_PASSWORD
Connect SnowSQL from prompt:

Sudo snowsql -a ix21114.ap-south-1

User: sreenivaskalahasti
Password:
* SnowSQL * v1.2.21
Type SQL statements or !help
sreenivaskalahasti#COMPUTE_WH@(no database).(no schema)>!help
+------------+-------------------------------------------+-------------+------------------------------------------------------------------------------------------
--+
| Command | Use | Aliases | Description |
|------------+-------------------------------------------+-------------+-------------------------------------------------------------------------------------------
-|
| !abort | !abort <query id> | | Abort a query |
| !connect | !connect <connection_name> | | Create a new connection
|
| !define | !define <variable>=<value> | | Define a variable as the given value
|
| !edit | !edit <query> | | Opens up a text editor. Useful for writing longer queries. Defaults
to last query |
| !exit | !exit | !disconnect | Drop the current connection
|
| !help | !help | !helps, !h | Show the client help. |
| !options | !options | !opts | Show all options and their values
|
| !pause | !pause | | Pauses running queries. |
| !print | !print <message> | | Print given text |
| !queries | !queries help, <filter>=<value>, <filter> | | Lists queries matching the specified filters. Write
<!queries> help for a list of filters. |
| !quit | !quit | !q | Drop all connections and quit SnowSQL
|
| !rehash | !rehash | | Refresh autocompletion |
| !result | !result <query id> | | See the result of a query |
| !set | !set <option>=<value> | | Set an option to the given value
|
| !source | !source <filename>, <url> | !load | Execute given sql file
|
| !spool | !spool <filename>, off | | Turn on or off writing results to file
|
| !system | !system <system command> | | Run a system command in the shell
|
| !variables | !variables | !vars | Show all variables and their values
|
+------------+-------------------------------------------+-------------+------------------------------------------------------------------------------------------
--+
sreenivaskalahasti#COMPUTE_WH@(no database).(no schema)>use TRAINING_DB;
+----------------------------------+
| status |
|----------------------------------|
| Statement executed successfully. |
+----------------------------------+
1 Row(s) produced. Time Elapsed: 0.740s
sreenivaskalahasti#COMPUTE_WH@TRAINING_DB.PUBLIC>show databases;
+-------------------------------+-----------------------+------------+------------+-------------------------+--------------+------------------------------------
---------------+---------+----------------+
| created_on | name | is_default | is_current | origin | owner | comment
| options | retention_time |
|-------------------------------+-----------------------+------------+------------+-------------------------+--------------+-------------------------------------
--------------+---------+----------------|
| 2022-01-09 05:50:52.078 -0800 | OUR_FIRST_DATABASE | N |N | | ACCOUNTADMIN |
| |1 |
| 2022-01-02 08:12:50.161 -0800 | S3_TO_SNOWFLAKE |N |N | | ACCOUNTADMIN |
| |1 |
| 2022-01-01 06:52:23.299 -0800 | SNOWFLAKE |N |N | SNOWFLAKE.ACCOUNT_USAGE | |
| |1 |
| 2022-01-01 06:52:27.797 -0800 | SNOWFLAKE_SAMPLE_DATA | N |N | SFC_SAMPLES.SAMPLE_DATA |
ACCOUNTADMIN | Provided by Snowflake during account provisioning | |1 |
| 2022-01-09 05:47:44.610 -0800 | TRAINING_DB |N |Y | | ACCOUNTADMIN |
| |1 |
+-------------------------------+-----------------------+------------+------------+-------------------------+--------------+------------------------------------
---------------+---------+----------------+
5 Row(s) produced. Time Elapsed: 0.156s
sreenivaskalahasti#COMPUTE_WH@TRAINING_DB.PUBLIC>show TABLES;
+-------------------------------+-----------+---------------+-------------+-------+---------+------------+------+-------+--------------+----------------+---
-------------------+-----------------+---------------------+------------------------------+---------------------------+-------------+
| created_on | name | database_name | schema_name | kind | comment | cluster_by | rows | bytes |
owner | retention_time | automatic_clustering | change_tracking | search_optimization |
search_optimization_progress | search_optimization_bytes | is_external |
|-------------------------------+-----------+---------------+-------------+-------+---------+------------+------+-------+--------------+----------------+----
------------------+-----------------+---------------------+------------------------------+---------------------------+-------------|
| 2022-01-09 05:49:55.808 -0800 | EMP_BASIC | TRAINING_DB | PUBLIC | TABLE | | | 0| 0|
ACCOUNTADMIN | 1 | OFF | OFF | OFF | NULL | NULL |
N |
+-------------------------------+-----------+---------------+-------------+-------+---------+------------+------+-------+--------------+----------------+---
-------------------+-----------------+---------------------+------------------------------+---------------------------+-------------+
1 Row(s) produced. Time Elapsed: 0.163s
sreenivaskalahasti#COMPUTE_WH@TRAINING_DB.PUBLIC>use OUR_FIRST_DATABASE;
+----------------------------------+
| status |
|----------------------------------|
| Statement executed successfully. |
+----------------------------------+
1 Row(s) produced. Time Elapsed: 0.143s
sreenivaskalahasti#COMPUTE_WH@OUR_FIRST_DATABASE.PUBLIC>show tables;
+-------------------------------+--------------+--------------------+-------------+-------+---------+------------+------+-------+--------------+-------------
---+----------------------+-----------------+---------------------+------------------------------+---------------------------+-------------+
| created_on | name | database_name | schema_name | kind | comment | cluster_by | rows |
bytes | owner | retention_time | automatic_clustering | change_tracking | search_optimization |
search_optimization_progress | search_optimization_bytes | is_external |
|-------------------------------+--------------+--------------------+-------------+-------+---------+------------+------+-------+--------------+--------------
--+----------------------+-----------------+---------------------+------------------------------+---------------------------+-------------|
| 2022-01-09 05:52:24.313 -0800 | LOAN_PAYMENT | OUR_FIRST_DATABASE | PUBLIC | TABLE | | | 0
| 0 | ACCOUNTADMIN | 1 | OFF | OFF | OFF | NULL |
NULL | N |
+-------------------------------+--------------+--------------------+-------------+-------+---------+------------+------+-------+--------------+-------------
---+----------------------+-----------------+---------------------+------------------------------+---------------------------+-------------+
1 Row(s) produced. Time Elapsed: 0.144s
sreenivaskalahasti#COMPUTE_WH@OUR_FIRST_DATABASE.PUBLIC>SELECT CURRENT_WAREHOUSE();
+---------------------+
| CURRENT_WAREHOUSE() |
|---------------------|
| COMPUTE_WH |
+---------------------+
1 Row(s) produced. Time Elapsed: 0.144s
sreenivaskalahasti#COMPUTE_WH@OUR_FIRST_DATABASE.PUBLIC>use WAREHOUSE TRAINING_WH;
+----------------------------------+
| status |
|----------------------------------|
| Statement executed successfully. |
+----------------------------------+
1 Row(s) produced. Time Elapsed: 0.146s
sreenivaskalahasti#TRAINING_WH@OUR_FIRST_DATABASE.PUBLIC>SELECT CURRENT_WAREHOUSE();
+---------------------+
| CURRENT_WAREHOUSE() |
|---------------------|
| TRAINING_WH |
+---------------------+
1 Row(s) produced. Time Elapsed: 0.290s
sreenivaskalahasti#TRAINING_WH@OUR_FIRST_DATABASE.PUBLIC>SELECT CURRENT_SCHEMA();
+------------------+
| CURRENT_SCHEMA() |
|------------------|
| PUBLIC |
+------------------+
1 Row(s) produced. Time Elapsed: 2.137s
sreenivaskalahasti#TRAINING_WH@OUR_FIRST_DATABASE.PUBLIC>

You might also like