如何从Python将雪花中的绑定变量传递给copy into语句

时间:2020-03-18 16:22:26

标签: python snowflake-cloud-data-platform

.execute(“从@ cdp_json_acpt / data / 1 file_format =(type = json)复制到tmp_cdp_score_feature中”

因为最后一个值将在1到100之间变化,例如data / 2,data / 3,所以我需要将其作为变量传递。

类似

.execute(“从“ @ cdp_json_acpt / data /(%s)file_format =(type = json),(2)复制到tmp_cdp_score_feature中”

2 个答案:

答案 0 :(得分:0)

我认为您可能只是将双引号放在“类似”中的错误位置。绑定变量的格式也是参数选项

format: .execute("... WHERE my_column = %s", (value,)) 
pyformat: .execute("... WHERE my_column = %(name)s", {"name": value}) 
qmark: .execute("... WHERE my_column = ?", (value,)) 
numeric: .execute("... WHERE my_column = :1", (value,))

参考文档: https://docs.snowflake.com/en/user-guide/python-connector-api.html

答案 1 :(得分:0)

从@stg_json_acpt /“'%s'” file_format =(type = json),Force = True“%(des1)复制到tmp_stg

des1 = s3目标文件的路径 运行正常,经过测试