I am trying to create a new row that has an inventory, which is a 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)
I am then getting the following error:
"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"
DDL:
-- public.user definition
-- Drop table
-- DROP TABLE public.user;
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)
);
What might be the issue?
It looks like there was a bug in the JSONBArray. It should never have had pgtype.Text elements. It should have had pgtype.JSONB elements. I don't think that ever worked... 馃槩
I've corrected this on master of the pgtype library. Try this: go get github.com/jackc/pgtype@79b0521. So I think it should work for you once you change the elements to the proper type. Let me know if that fixes it.
Most helpful comment
It looks like there was a bug in the
JSONBArray. It should never have hadpgtype.Textelements. It should have hadpgtype.JSONBelements. I don't think that ever worked... 馃槩I've corrected this on master of the pgtype library. Try this:
go get github.com/jackc/pgtype@79b0521. So I think it should work for you once you change the elements to the proper type. Let me know if that fixes it.