ProgrammingError:(1064,..)以正确的语法在第1行的'))'附近使用“])

问题描述 投票:1回答:1

我正在尝试使用AWS lambda查询RDS实例。我正在用python编码。

我的插入查询是:

with conn.cursor() as cur:
 cur.execute("""insert into DocumentLanguagesInfo (documentId, version, language1, 
 language1Confidence, language2, language2Confidence, language3, language3Confidence, 
 otherLanguages) values(%s, %s, %s, %s, %s, %s, %s, %s, %s)""", (docId, version, lang1, 
 lang1Conf, lang2, lang2Conf, lang3, lang3Conf, otherLangs))

conn是用于成功连接到SQL Server的连接变量。

但是当我执行此查询时,我在cloudwatch中收到以下错误:

[ERROR] ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1")
Traceback (most recent call last):
  File "/var/task/sqlConnection.py", line 100, in lambda_handler
    cur.execute("""insert into DocumentLanguagesInfo (documentId, version, language1, language1Confidence, language2, language2Confidence, language3, language3Confidence, otherLanguages) values(%s, %s, %s, %s, %s, %s, %s, %s, %s)""", (docId, version, lang1, lang1Conf, lang2, lang2Conf, lang3, lang3Conf, otherLangs))

我尝试以这种方式编写代码,但仍然会出现相同的错误:

with conn.cursor() as cur:
        sql_query = "insert into DocumentLanguagesInfo (documentId, version, language1, language1Confidence, language2, language2Confidence, language3, language3Confidence, otherLanguages) values(%s, %s, %s, %s, %s, %s, %s, %s, %s)"
        recordTuple = (docId, version, lang1, lang1Conf, lang2, lang2Conf, lang3, lang3Conf, otherLangs)

        cur.execute(sql_query, recordTuple)
        conn.commit()

此查询中我在做什么错?

python mysql aws-lambda amazon-rds
1个回答
0
投票

我认为问题可能出在otherLangs中。也许使用

recordTuple = (docId, version, lang1, lang1Conf, lang2, lang2Conf, lang3, lang3Conf, tuple(otherLangs)) 

会更好。

© www.soinside.com 2019 - 2024. All rights reserved.