Snowflake Snowsql Exit Codes for Unix/Linux Systems

  • Post author:
  • Post last modified:March 13, 2020
  • Post category:Snowflake
  • Reading time:4 mins read

Snowsql is a command line interface written on the top of the Snowflake Python connector. The interface is a pure Python tool. Similar to many relational database tools, Snowsql also returns several exit codes. In this article, we will check Snowflake Snowsql exit codes for Unix or Linux system.

Snowflake Snowsql Exit Codes

The Snowsql exit code are very much important when you are working with a script such as ETL/ELT.

Snowflake Snowsql exit codes provide the information about the execution status of the SQL queries or commands.

SnowSQL returns several possible exit codes when it exits or quits. When you are executing SQL queries interactively at the SnowSQL prompt either by using -q or -f options, the command returns one of the following exit codes:

  • 0: Everything ran smoothly.
  • 1: Something went wrong with the client.
  • 2: Something went wrong with the command line arguments.
  • 3: SnowSQL could not contact the server.
  • 4: SnowSQL could not communicate properly with the server.
  • 5: The exit_on_error configuration option was set and SnowSQL exited because of an error.

How to Capture SnowSQL Exit Codes?

On a bash, it is really easy to check the status of the last executed command. Simply check the content of ‘$?’. You can use the bash echo command to display the content of the variable.

However, it is different if you are using a Windows operating system.

SnowSQL Exit Code Examples

To check the exit codes, we will be executing several SQL commands.

For examples, consider following examples which returns the exit code 0. That means the query is executed successfully without any issue.

vithal@vithal-B0100I:~$ snowsql -c myconnection -D var=TEST1 -o variable_substitution=True -o quiet=True -q 'select * from test1'

vithal@vithal-B0100I:~$ echo $?
0

As you can see the exit code is 0. No error with query.

Now, let us set exit_on_error=True and check exit code.

For example,

vithal@vithal-B0100I:~$ snowsql -c myconnection -o exit_on_error=true -o quiet=True -q "select inexistent_function()"
002140 (42601): SQL compilation error:
Unknown function INEXISTENT_FUNCTION

vithal@vithal-B0100I:~$ echo $?
5

You can use these exit codes in your bash script to control the execution flow.

Related Articles,

Hope this helps 🙂