Alandroid
Alandroid

Reputation: 31

golang pass in args (a slice of strings) as "args ... interface{}"

Here is my code:

package main

import (
    "database/sql"
)

func main() {
    table := "some table"

    args := []interface{}{"string1", "string2", "string3", "string4"}

    _, err := db.Exec( "INSERT INTO" + table + "VALUES('', ?, ?, ?, ?)", args)
        if err != nil {
            return err
        }
}

I want to pass in the args but cannot format them as "args ...interface{}"

Current output is:

sql: converting Exec argument #0's type: unsupported type []interface {}, a slice

Thanks in advance!

Upvotes: 2

Views: 6243

Answers (1)

Andy Schweig
Andy Schweig

Reputation: 6749

In the db.Exec call, use args... instead of args.

Upvotes: 14

Related Questions