我希望能够在使用Go进行历史记录的表中编写bigint数组。不幸的是,当我这样做时会抛出错误sql:converting Exec argument #1's type: unsupported type []int64, a slice
。以下是我为了简洁而编辑过的代码:
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 主键,productids bigint[] 非空,cardid bigint 非空,salepoint int
请注意保留HTML标签。
lib/pq
库当前不处理数组类型,尽管有一个功能请求:https://github.com/lib/pq/issues/49 - dyoo