How to insert array field with parameter?

golang with pq.

table
id . SERIAL
nums INT ARRAY

INSERT INTO table(nums) values ($1) ( $1 = []int64{1,2,3} )
But it doesn’t work, error: sql: converting argument $1 type: unsupported type []int64, a slice of int64

i am convert $1 to string ARRAY[1,2,3] or [1,2,3]
It doesn’t work, error: pq: error in argument for $1: unsupported OID 2277 with format code formatText

What happens when you try the same thing on PostgreSQL?

I didn’t use postgresql, on cockroachdb fault it is.

Hi Jorise, instead of using []int64{1,2,3} or a bracketed string, try using a string with curly braces: "{1,2,3}". The pq driver will convert this into an array to send over the wire. The below works for me with both PostgreSQL and CockroachDB 1.1:

db.Exec("CREATE TABLE foo (x INT ARRAY)")
db.Exec("INSERT INTO foo VALUES ($1)", "{1,2,3}")
db.Exec("CREATE TABLE foo (x INT ARRAY)")
db.Exec("INSERT INTO foo VALUES ($1)", "{1,2,3}")

it works.

db.Exec("CREATE TABLE foo (x FLOAT ARRAY)")
db.Exec("INSERT INTO foo VALUES ($1)", "{1.0,2.0,3.0}")

it didn’t work. i got this error:
pq: error in argument for $5: unsupported OID 2277 with format code formatText

cockroach 1.1 stable