[英]How to scan SQL array to []int64 in Go?
I am scanning an array of int from Postgres DB and it is returning as []uint8
. 我正在从Postgres DB扫描一个int数组,它返回为
[]uint8
。 I need them in []int64
, how can I convert them into []int64
or how can I return them from the DB as []int64
? 我在
[]int64
需要它们,如何将它们转换为[]int64
或如何从数据库中以[]int64
返回它们? In my query I am selecting using the Array function in Postgres: Array(col1)
where col1 is serial. 在我的查询中,我选择使用Postgres中的Array函数:
Array(col1)
其中col1是串行的。
The error I am getting is: 我得到的错误是:
unsupported Scan, storing driver.Value type []uint8 into type []int64
If you're using github.com/lib/pq
, just use Int64Array
. 如果您使用的是
github.com/lib/pq
,则只需使用Int64Array
。
col1arr := []int64{}
arr := pq.Int64Array{}
err := rows.Scan(&arr)
// ...
col1arr = []int64(arr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.