【问题标题】:ProgrammingError: syntax error at or near "," in psycopg2 update query using extras.execute_valuesProgrammingError:在使用 extras.execute_values 的 psycopg2 更新查询中“,”处或附近的语法错误
【发布时间】:2019-05-26 05:27:13
【问题描述】:

我正在尝试使用 psycopg2.extras.execute_values 模块更新 Redshift 表。下面是代码

from psycopg2 import extras
cur = con.cursor()

update_query = """update my_table
                  set gender = data.gender 
                  from (VALUES %s) as data (gender,firstname) 
                  where my_table.firstname = data.firstname
                  and my_table.gender is NULL"""

new_values = [("F","Charlene"),("F","BRITTANY")]

extras.execute_values (cur, update_query, new_values)

但是我得到以下错误:

尝试了各种引号、双引号和括号的组合,但没有成功。

TIA。

  • 罗汉

【问题讨论】:

  • 先试试new_values = ("F","Charlene")
  • Getting "TypeError: not all arguments convert during string formatting" 错误 new_values = ("F","Charlene")
  • @prashantrana 也尝试过new_values = [("F","Charlene")],错误是 ProgrammingError: syntax error at or near ")" LINE 3: from (VALUES ('F','Charlene') ) 作为数据(pr...
  • 这在 Postgres 9.5 和 11 中都能完美运行。检查 Redshift 中的语法是否正确。
  • @klin 我使用的版本是 ('PostgreSQL 8.0.2 on i686-pc-linux-gnu, 由 GCC gcc (GCC) 3.4.2 编译 20041017 (Red Hat 3.4.2-6 .fc3), Redshift 1.0.5463',)

标签: python postgresql sql-update amazon-redshift psycopg2


【解决方案1】:

我迟到了,但这是我得到的答案。

cursor.executemany().

我尝试进行大量搜索,但我自己从未找到解决方案。我正在使用 python。

更多详情请见以下网址。

  1. https://github.com/psycopg/psycopg2/issues/830
  2. https://zetcode.com/python/psycopg2/(cursor.executemany()的详细用例)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多