Python psycopg2错误表示在插入文本/字符串时插入整数

Python psycopg2错误表示在插入文本/字符串时插入整数,python,sql,psycopg2,psql,Python,Sql,Psycopg2,Psql,当我从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',

当我从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);
您的SQL查询是:

insert into matches
    values(%s ,%s, %s, %s)
(然后是值)

这是一种糟糕的形式,因为插入顺序取决于列的声明顺序

使用
insert
时,应明确列出列,因此SQL如下所示:

insert into matches(player1, player2, player1_result, player2_result)
    values(%s ,%s, %s, %s)
在你的声明中,这是:

DB.execute("insert into matches(player1, player2, player1_result, player2_result) values(%s ,%s, %s, %s)", (player1, player2, player1_result, player2_result))

首先,尝试在
insert
语句中显式列出列。哦,如果你是指通过查询列出来,我不能,因为表是空的,我的意思是使用
insert插入匹配项(player1、player2、player1\u结果、player2\u结果)
使用
insert
时,您几乎应该始终包含列的显式列表。哦,对不起,我不知道该怎么做。但是,我刚刚解决了我的问题,问题是“win”被插入到“player2”中,因为“player1”参数被插入到“match_ID”列中,因为没有明确说明值应该插入到哪些列中。我认为不能在序列列中插入任何内容。您能告诉我如何在insert语句中显式声明列吗?