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

BalajiAWS
  • 137
  • 1
  • 12
  • Glad to hear that. In this case, could you mark the answer as correct? so other people knows that the question is answered. – Gokhan Atil Nov 30 '20 at 11:26

1 Answers1

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
Gokhan Atil
  • 9,278
  • 2
  • 11
  • 24
  • in more recent versions of snowsql you will have to add `-o echo=False`, otherwise your SQL query will be returned as well – dovregubben Mar 08 '23 at 16:01