将Snowflake表中的值存储到Python变量中

huangapple go评论67阅读模式
英文:

store values from snowflake table into variable in python

问题

我需要从Snowflake表中获取值,并使用Python将其存储到变量中。
之后,我需要将该值与文件名(product_yyyymmdd.csv)合并。

以下是我的代码:

HA_file_path = '''select CONFIG_VALUE from CONFIGURATIONS where CONFIG_NAME ='HA' '''

file_path = cs.execute(HA_file_path)

它没有返回任何值,而是打印了类似于以下内容:

snowflake.connector.cursor.SnowflakeCursor object at 0x7fefbe68a070

有任何帮助吗?

英文:

i need to get value from snowflake table and store into variable using python.
after that i need to merge that value with file name(product_yyyymmdd.csv).

below is my code
HA_file_path = ''' select CONFIG_VALUE from CONFIGURATIONS where CONFIG_NAME =\ 'HA''''
-- syntax is correct

file_path = cs.execute(HA_file_path)

its not returning any value and printing something like this :

snowflake.connector.cursor.SnowflakeCursor object at 0x7fefbe68a070

any help!

答案1

得分: 0

在这一行中:file_path = cs.execute(HA_file_path),你将一个变量分配给了游标对象,但你没有获取结果。如果你想将表中的一个值存储为变量,你可以在execute之后使用fetchone方法:

cs.execute(HA_file_path)
file_path = cs.fetchone()[0]

print(file_path)
英文:

In the line: file_path = cs.execute(HA_file_path) you assigned a variable to the cursor object, but you are not fetching results. If you want to store just one value from the table as a variable, you can use fetchone method after execute:

cs.execute(HA_file_path)
file_path = cs.fetchone()[0]

print(file_path)

huangapple
  • 本文由 发表于 2023年7月14日 00:40:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定