我正在尝试使用 psycopg2 executemany 进行简单的多插入,但我只能使用 dict 而不是“普通”值序列使其工作:
# given:
values = [1, 2, 3] ; cursor = conn.cursor()
# this raises TypeError: 'int' object does not support indexing:
cursor.executemany('INSERT INTO t (col_a) VALUES ( %s )', values)
# I also tried encapsulating my 'values' into a tuple/list but it gives another exception (TypeError: not all arguments converted during string formatting).
# while this is ok:
cursor.executemany('INSERT INTO t (col_a) VALUES ( %(value)s )', [ dict(value=v) for v in values ])
不使用“命名”参数 (%(value)s) 就不能给出一个“简单”的值列表/元组吗?