Golang database/sql.Rows.Columns function example

package database/sql

Columns returns the column names. Columns returns an error if the rows are closed, or if the rows are from QueryRow and there was a deferred error.

Golang database/sql.Rows.Columns function usage example

 var rows *sql.Rows
 var cols []string
 rows, err = dbmap.Db.Query("SELECT * FROM created_columns")
 cols, err = rows.Columns() // <--- here
 if err != nil || len(cols) != 2 {
 fmt.Println("Expected column not found")
 }

Reference :

http://golang.org/pkg/database/sql/#Rows.Columns

Advertisement