Skip to content
Advertisement

Go SQL, scanning a row as a slice?

closing note: This question does not ask “how can I find the number of columns returned?” which is len(row.Columns()). It is asking a Go-related question concerning the rows.Scan() function.

How can I extract all the columns in a row into a slice or equivalent? For example

I would like to extract the data in lastcols as a slice.

context:

  • for debugging, I would like to select * from sometable and display the results without knowing the table format in advance.
  • github.com/lib/pg SQL driver.

Advertisement

Answer

You can find the Columns with rows.Columns() then you can make a slice to fetch the data.

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