我希望能够将一个bigint数组写入一个表中,以便在Go中用于历史记录.不幸的是,我不能这样做,当我这样做的错误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);
}

以下是我希望插入的表格 struct :

推荐答案

实现数据库/sql/driver.具有自定义类型的估价师:

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.
}

Postgresql相关问答推荐

带有regex表达式的Postgres SQL

在SqlalChemy中转义动态CamelCase场

DBT-DBT依赖于未找到的源

单个WAL文件中的操作会影响哪些表和多少行

在Postgres中如何连接具有相同名称列的表并更改列名称?

Npgsql中准备好的语句和参数化查询有什么区别?

如何在 MockDataProvider 中创建自定义 JOOQ 记录?

Postgres 查询计划器不会使用更便宜的复合索引

如何使用 SQLAlchemy 将列默认设置为 PostgreSQL 函数?

如何在 PostgreSQL hstore 中使用通配符查询值

从 Postgres 字段中的多个值中进行 Select

Heroku PGError:operator does not exist: character varying = integer

Postgres - 如果找不到记录,则在更新时返回错误

在 PostgreSQL 中跳过每 n 个结果行

从长时间的postgres转换日期

如何为 Postgres psql 设置时区?

防止 PostgreSQL 中的递归触发器

处理用户发送的string contains null byte

使用 Spring、Hibernate 和 C3P0 管理多租户 Web 应用程序中的连接池

PostgreSQL 多种认证方式