I am trying to perform the following type of query in golang using the sql library:
rows, err := db.Query("select * from someTable where age = ? and hairColor = ?", age,haircolor)
But get the following sort of error:
Error occured: sql: expected 1 arguments, got 2
How do I perform an SQL select statement in golang where there are multiple values in the WHERE clause?
The answer is to use a prepared statement so in my example here:
stmt, err := db.Prepare("select * from someTable where age = ? and hairColor = ?")
rows, err := stmt.Query(age,hairColor)
This seems obvious in retrospect. Hopefully this can save somebody a few minutes of hair pulling in the future!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With