我正在尝试插入一个具有inventory
with 数据类型的新行jsonb[]
:
elements := []pgtype.Text{{String: `{"adsda": "asdasd"}`, Status: pgtype.Present}}
dimensions := []pgtype.ArrayDimension{{Length: 1, LowerBound: 1}}
inventory := pgtype.JSONBArray{Elements: elements, Dimensions: dimensions, Status: pgtype.Present}
row = db.pool.QueryRow(context.Background(), `INSERT INTO user ("email", "password", "inventory") VALUES($1, $2, $3) RETURNING uuid, email, "password"`, requestEmail, requestPassword, inventory)
但我收到以下错误:
"Severity": "ERROR",
"Code": "42804",
"Message": "wrong element type",
"Detail": "",
"Hint": "",
"Position": 0,
"InternalPosition": 0,
"InternalQuery": "",
"Where": "",
"SchemaName": "",
"TableName": "",
"ColumnName": "",
"DataTypeName": "",
"ConstraintName": "",
"File": "arrayfuncs.c",
"Line": 1316,
"Routine": "array_recv"
Postgres 表定义:
CREATE TABLE public.user (
uuid uuid NOT NULL DEFAULT uuid_generate_v4(),
email varchar(64) NOT NULL,
"password" varchar(32) NOT NULL,
inventory _jsonb NULL,
CONSTRAINT user_pk PRIMARY KEY (uuid)
);
可能是什么问题?任何想法都会有所帮助。