1

how do we assign SNOWSQL select query output to an unix variable, i am using below shellscript and trying to assign the output of select statement to variable var2. but somehow it is not working.

#!/bin/ksh set var2=(snowsql -c newConnection -o log_level=DEBUG -o log_file=~/snowsql_sso_debug.log -r DEV_ACCT_ROLE -w LOAD_WH -d DEV_DB -s CTL_DB -q "select STG_TBL_NAME from CTL_DB.PROC_CTRL WHERE STG_TBL_NAME='TEAM'")

appriciate your quick response. Thanks

1
  • Glad to hear that. In this case, could you mark the answer as correct? so other people knows that the question is answered. Commented Nov 30, 2020 at 11:26

1 Answer 1

3

I can get the result using $(), but you should also use some additional options to suppresses header, timing, and the startup and exit messages.

https://docs.snowflake.com/en/user-guide/snowsql-config.html#snowsql-configuration-options-reference

VAR2=$(snowsql -c myconnection -q "SELECT max(v) FROM Z" -o friendly=False -o header=False -o output_format=plain -o timing=False)

echo $VAR2
20200210
Sign up to request clarification or add additional context in comments.

1 Comment

in more recent versions of snowsql you will have to add -o echo=False, otherwise your SQL query will be returned as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.