【发布时间】:2023-03-30 16:39:01
【问题描述】:
当我从我的 python 应用程序运行此查询时
DB.execute("insert into matches values(%s ,%s, %s, %s)", (player1, player2, player1_result, player2_result,))
我收到此错误
psycopg2.DataError: invalid input syntax for integer: "win"
LINE 1: insert into matches values(689 ,690, 'win', 'lose')
^
player1、player2、player1_result 和 player2_result 是这里给包含函数的参数
reportMatch(id1, id2, "win", "lose")
这是表定义
create table matches ( player1 serial references players, player2 serial references players, player1_result text, player2_result text, match_ID serial primary key);
【问题讨论】:
-
首先,尝试在
insert语句中明确列出列。 -
哦,如果你的意思是通过查询来列出它们,我不能,因为表是空的
-
不,我的意思是使用
insert into matches(player1, player2, player1_result, player2_result) . . .使用insert时,您应该几乎总是包含明确的列列表。 -
哦,对不起,我真的不知道该怎么做。但是,我刚刚解决了我的问题,问题是“win”被插入到“player2”中,因为“player1”参数被插入到“match_ID”列中,因为没有明确说明值应该是哪些列插入到。我认为没有任何东西可以插入串行列。你能告诉我如何在我的插入语句中显式声明列吗?