Maybe surprisingly I can't use ellipsis at the call site because Scan 
expects pointers to values, not the values themselves.

Using v... Scan returned an error:

    sql: Scan error on column index 0: destination not a pointer

So, I changed v to contain pointer to values. Then it worked.

v = make([]interface{}, size)
sv = make([]string, size)
for i := 0; i < size; i++ {
v[i] = &sv[i]
}

err = rows.Scan(v...) // Scan indirectly fills sv

Thank you, Ayan.

On Monday, April 3, 2017 at 10:27:29 AM UTC-3, Ayan George wrote:
>
>
>
> On 04/03/2017 08:50 AM, oju...@gmail.com <javascript:> wrote: 
> > I built a little command line utility for running arbitrary sql queries. 
> > You use it like: 
> > 
> >     runQuery "select * from myTable" 
> > 
> > 
> > Previously I have build similar tools in C and Java and I don't remember 
> > needing to code a hack to handle a variable number of columns. 
> > 
> >     https://play.golang.org/p/6WOu1SzgcZ 
> > 
>
> Just going from the documentation, rows.Scan() is a variadic function so 
> you should be able to do something like: 
>
>   cols, _ := rows.Columns() 
>   v := make([]interface{}, len(cols)) 
>   err = rows.Scan(v...) 
>
> -ayan 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to