简体   繁体   English

将数据从 SQL 服务器传输到雪花时在 python 上出错

[英]Getting error on python while transferring data from SQL server to snowflake

I am getting below error我得到以下错误

query = command % processed_params TypeError: not all arguments converted during string formatting查询 = 命令 % 处理参数类型错误:并非所有参数都在字符串格式化期间转换

I am trying to pull data from SQL server and then inserting it into Snowflake my below code我正在尝试从 SQL 服务器中提取数据,然后将其插入雪花我下面的代码

import pyodbc
import sqlalchemy
import snowflake.connector
driver = 'SQL Server'
server = 'tanmay'
db1 = 'testing'
tcon = 'no'
uname = 'sa'
pword = '123'

cnxn = pyodbc.connect(driver='{SQL Server}', 
                      host=server, database=db1, trusted_connection=tcon,
                      user=uname, password=pword)
cursor = cnxn.cursor()
cursor.execute("select * from Admin_tbldbbackupdetails")
rows = cursor.fetchall()
#for row in rows:
 # #data = [(row[0], row[1],row[2], row[3],row[4], row[5],row[6], row[7])]
print (rows[0])  
cnxn.commit()
cnxn.close()

connection = snowflake.connector.connect(user='****',password='****',account='*****')

cursor2 = connection.cursor()
cursor2.execute("USE WAREHOUSE FOOD_WH")
cursor2.execute("USE DATABASE Test")
sql1="INSERT INTO CN_RND.Admin_tbldbbackupdetails_ip"
"(id,dbname, dbpath, backupdate, backuptime, backupStatus, FaildMsg, Backupsource)"
"values (?,?,?,?,?,?,?,?)"
cursor2.execute(sql1,*rows[0])

It's obviously string parsing error.这显然是字符串解析错误。 You missed to provide parameter to %s printout.您没有为%s打印输出提供参数。

If you cannot fix it step back and try another approach.如果您无法修复它,请退后一步并尝试另一种方法。 Use another script to achieve the same and get back to you bug tomorrow :-)使用另一个脚本来实现相同的功能,并在明天回复您的错误:-)

My script is doing pretty much the same:我的脚本几乎是一样的:

1. Connect to SQL Server
    -> fetchmany
        -> multipart upload to s3
            -> COPY INTO Snowflake table

Details are here: Snowpipe-for-SQLServer详细信息在这里: Snowpipe-for-SQLServer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在python中执行snowflake SQL语句时snowflake-python错误 - snowflake-python error while executing snowflake SQL statement in python 将数据从 sqlite 传输到 elasticsearch 时出错 - Error while transferring data from sqlite to elasticsearch 从雪花获取json数据到python - Getting json data from snowflake to python 未从 Python 中的 SQL 服务器获取预期数据 - Not getting expected data from SQL Server in Python 获取 ModuleNotFoundError: No module named 'snowflake', while using Python to load data - Getting ModuleNotFoundError: No module named 'snowflake', while using Python to load data 从CSV到mysql传输数据时发生日期时间错误 - date time error while transferring data from csv to mysql 从python服务器获取数据时出现jQuery Jtable错误 - I am getting jQuery Jtable error while fetching data from the python server 如何通过 python 雪花连接器处理 Unicode 字符问题,同时从雪花读取数据 - How to handle Unicode character issues through python snowflake connector, while reading data from snowflake 使用 python 中的 Airflow 触发 SQL 时出现模板错误? - Getting Template Error while triggering SQL using Airflow from python? 使用boto将文件从ec2传输到s3时出错 - Getting error while transferring files from ec2 to s3 using boto
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM