Sql: converting argument $1 type: unsupported type [3]int64, a array

(akhil) #1

My function definition is

func (s *Stmt) CheckNamedValue(nv *driver.NamedValue) (err error) {
	switch d := nv.Value.(type) {
        case []int64:
                err = nil
		nv.Value, err = driver.DefaultParameterConverter.ConvertValue(nv.Value)
	return err

This is function works fine if I pass []int64 but not [size]int64.
I am checking the type but why it is the above two are different?


(akhil) #2

can any one help me on this?:disappointed::tired_face:

(Holloway) #3

Go is static type so it is very strict with data type itself. []int64 is a slice (keeping it simple: "imagine it as a basket full of arrays to form “dynamic array”) while [size]int64 is an array. Since they are 2 different data types, Go will throw an error.

To fix this, you can easily convert any existing array into slice using the slice bound [:].

a := [size]int64{ ... }
x := a[:] // x is now []int64 type

(Holloway) #4

All good there?

(akhil) #5

Thanks…It is working sorry for the late reply.