Snowflake Snowsql Windows System Exit Codes

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

In my other article, Snowflake Snowsql Exit Codes for Unix/Linux Systems, we have discussed on SnowSQL exit codes for Linux systems. But, many developers prefer to use a Windows system. In this article, we will check Snowflake Snowsql windows system exit codes and how to capture them on a Windows command prompt.

Snowflake Snowsql Windows System Exit Codes

SnowSQL command line interface for Snowflake is written in pure Python. You can download the msi installer and install same on your Windows machine. The configuration is pretty much similar to that of Linux setup.

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 Windows?

On a Windows system, it is easy to check the status of the last executed command. Simply check the content of ‘%errorlevel%’ variable. You can use the bash echo command to display the content of the variable.

However, it is different if you are using Linux/Unix operating systems.

SnowSQL Exit Code on Windows Examples

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

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

C:\Users\viths>snowsql -c myconnection -D var=TEST1 -o variable_substitution=True -o quiet=True -q "select * from test1"

C:\Users\viths>echo %errorlevel%
0

As you can see the exit code is 0. There no error while processing input query.

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

For example,

C:\Users\viths>snowsql -c myconnection -o exit_on_error=true -o quiet=True -q "select inexistent_function()"
002140 (42601): SQL compilation error:
Unknown function INEXISTENT_FUNCTION

C:\Users\viths>echo %errorlevel%
5

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

Related Articles,

Hope this helps 🙂