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');

私が間違っていることを誰かが理解するのを手伝ってくれますか?

4

2 に答える 2

1

後の数字$は、パラメーターの順序を示します。

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);
于 2013-03-04T17:14:24.263 に答える
1

単に値を挿入しようとしていて、最初のフィールド値を指定していない場合は、挿入先の列を指定する必要があります。

あなたの列が何と呼ばれているのかわからないので、column_1、column_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);
于 2013-03-04T17:14:45.130 に答える