我希望能够将bigints数组写入要用于Go历史记录的表中。不幸的是,我不能,当我这样做时`sql: converting Exec argument
type Card struct { cid int64 } type Transaction struct { tid, cardid int64 productids []int64 salepoint int cardkey string } func logPurchase(card *Card, t *Transaction) { _, err := db.Exec("INSERT INTO history VALUES ($1, $2, $3, $4)", rand.Int63(), t.productids, card.cid, t.salepoint); }
这是我要插入的表的结构: tid bigint primary key, productids bigint[] not null, cardid bigint not null, salepoint int
tid bigint primary key, productids bigint[] not null, cardid bigint not null, salepoint int
使用自定义类型实现database / sql / driver.Valuer:
type int64array []int64 func (a int64array) Value() (driver.Value, error) { // Format a in PostgreSQL's array input format {1,2,3} and return it as as string or []byte. }