我的雪花表中有一個列,其中包含帶空格的值
select distinct ("power") from "dev"."devtable"."devschema"
------------------
demo1 is good
what are you doing
thank you stack
----------------------
但需要與不帶空格的串列陣列以及引號和逗號進行比較:
["demo1_is_good",
"thank_you_stack",
"what_are_you_doing"]
我想將python與雪花一起使用,此比較的目的是通過首先洗掉引號并回圈每個串列來檢查例如'demo1_is_good'(列值)是否與'demo1 is good'(陣列中的串列值)相同與列中的記錄進行比較。
如果任何串列不在列中,則腳本將退出并且不繼續。
uj5u.com熱心網友回復:
在雪花表中搜索字串的代碼。找不到字串時退出。
import snowflake.connector
con = snowflake.connector.connect(
user='username',
password='password',
account='account_name.region',
warehouse='warehouse',
database='dbname',
schema='PUBLIC'
)
flag_not_exists = 0
tab_array = []
devarray = ['"demo1_is_good"', '"thank_you_stack"','"what_are_you_doing12"']
try:
cur = con.cursor()
cur.execute("select DISTINCT power as col1 from devtable;")
for col1 in cur:
tab_array.append(col1[0])
finally:
con.close()
for col1 in devarray:
for col2 in tab_array:
if (col2 == col1.replace('_',' ').replace('"','')):
flag_not_exists = 0
break
else:
flag_not_exists = 1
continue
if (flag_not_exists == 1):
break
else:
print ("Pass")
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/495466.html
