I need to process the SQL SELECT query, I don’t know how many columns I will receive, how can I send an arbitrary number of arguments to the database / sql package Scan function? You can certainly do this, but it looks too clumsy:
switch len(columns) { case 1: rows.Scan(&interfaces[0]) case 2: rows.Scan(&interfaces[0], &interfaces[1]) case 3: rows.Scan(&interfaces[0], &interfaces[1], &interfaces[2]) ... } This option also does not work:
interfaces := make([]*string, 0, len(coltype)) for range interfaces{ var str string interfaces = append(interfaces, &str) } rows.Next() rows.Scan(interfaces...) Mistake
cannot use interfaces (type [] * string) as type [] interface {} in argument to rows.Scan