Skip to content
Advertisement

sql: scan row(s) with unknown number of columns (select * from …)

I have a table t containing a lot of columns, and my sql is like this: select * from t. Now I only want to scan one column or two from the wide returned row set. However, the sql.Scan accepts dest ...interface{} as arguments. Does it mean I have to scan everything and use only the column I needed?

I know I could change the sql from select * to select my_favorite_rows, however, in this case, I have no way to change the sql.

Advertisement

Answer

You can make use of Rows.Columns, e.g.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement