SHUBHA SHREE
SHUBHA SHREE

Reputation: 1

Can i store select query result into a list variable in snowflake?

For Example,

set output_var;
select name from customer limit 5;

aaa
bbb
ccc
ddd
eee

is it possible to store this output into a variable(output_var), So that my output looks like

output_var = (aaa,bbb,ccc,ddd,eee)

Upvotes: 0

Views: 2368

Answers (2)

MKP
MKP

Reputation: 196

You can convert as below :

cur=snflk_conn.cursor() sql_query='select NAME from TEST"'

without Panda: result = cur.execute(sql_query) list1=[] for res in result: list1.append(res[0]) print(list1)

using Panda: df = pd.read_sql_query(sql_query, snflk_conn) print(df) print(df.values.tolist()) print(list(df['NAME']))

Upvotes: 0

Hans Henrik Eriksen
Hans Henrik Eriksen

Reputation: 2850

No, you can't store the result set from a query in anything other than a table in the Web GUI, or unload to cloud storage. Well, you can export a result set to CSV using the GUI, but SQL variables only accept constant expressions, not queries.

You can always use tables to store intermediate results, if you have the grants.

If you are using a client, eg. the Python client, you have access to result sets as a data stucture in the Python script and can use the data however you like.

Upvotes: 1

Related Questions