I'm using 'database/sql' module in Golang, trying to execute a query like:
select * from users
Note that it does not have any parameters. The method I'm using however forces you to have parameters in the arguments:
db.Query(query string, args)
So I'm forced to write something like:
db.Query("select * from users where 1=?", 1)
What's the way to run a query with no parameters?
func (db *DB) Query(query string, args ...interface{}) (*Rows, error)
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
If you are really using the database/sql
package, then the args
parameter is variadic:
The final incoming parameter in a function signature may have a type prefixed with .... A function with such a parameter is called variadic and may be invoked with zero or more arguments for that parameter.
So, the way to do it is simply:
db.Query("select * from users")