Postgresql Postgres:PreparedStatement未正确识别数据类型

Postgresql Postgres:PreparedStatement未正确识别数据类型,postgresql,insert,prepared-statement,auto-increment,Postgresql,Insert,Prepared Statement,Auto Increment,我无法正确执行此命令。表的第一列是一个自动递增的整数,因此我希望开始在第2列输入数据。当我执行以下操作时: PREPARE fooplan (text, smallint, smallint, text, date, timestamp with time zone) as INSERT INTO "table" VALUES($2, $3, $4, $5, $6, $7); EXECUTE fooplan('Add New Record', 2, 2, 'User', '1999-Jan-0

我无法正确执行此命令。表的第一列是一个自动递增的整数,因此我希望开始在第2列输入数据。当我执行以下操作时:

PREPARE fooplan (text, smallint, smallint, text, date, timestamp with time zone) as 
INSERT INTO "table" VALUES($2, $3, $4, $5, $6, $7);
EXECUTE fooplan('Add New Record', 2, 2, 'User', '1999-Jan-08', '04:05:06');
我得到这个错误:

SQL error:

ERROR:  column "category_id" is of type smallint but expression is of type text
LINE 2: insert into "MOP" values($2, $3, $4, $5, $6, $7);
                                     ^
HINT:  You will need to rewrite or cast the expression.
In statement:
prepare fooplan (text, smallint, smallint, text, date, time without time zone) as 
insert into "MOP" values($2, $3, $4, $5, $6, $7);
execute fooplan('Add New Mop', 2, 2, 'User', '1999-Jan-08', '04:05:06');

有人能帮我理解我做错了什么吗?

$
后面的数字表示参数顺序

INSERT INTO "table" VALUES($1, $2, $3, $4, $5, $6);
除此之外,您还必须命名要插入的列:

INSERT INTO "table" (col2, col3, col4, col5, col6, col7) 
VALUES($1, $2, $3, $4, $5, $6);

如果只是尝试插入值,但未指定第一个字段值,则需要说明要插入哪些列

我不知道你们的专栏叫什么,所以我把它们叫做专栏1,专栏2等等

prepare fooplan (text, smallint, smallint, text, date, timestamp with time zone)
INSERT INTO MOP(column_2, column_3, column_4, column_5, column_6, column_7) 
VALUES ($1, $2, $3, £4, $5, $6);