sql - "Operator does not exist: integer =?" when using Postgres with Golang -


i have simple sql query called within queryrow method provided go's database/sql package.

import (   "github.com/codegangsta/martini"   "github.com/martini-contrib/render"   "net/http"   "database/sql"   "fmt"   _ "github.com/lib/pq") )  type user struct {   name string }  func show(db *sql.db, params martini.params) {   id := params["id]   row := db.queryrow(     "select name users id=?", id)   u := user{}   err := row.scan(&u.name)   fmt.println(err) } 

however, i'm getting error pq: operator not exist: integer =? looks code doesn't understand ? placeholder. how can fix this?

postgresql works numbered placeholders ($1, $2, ...) natively rather usual positional question marks. documentation go interface uses numbered placeholders in examples:

rows, err := db.query("select name users age = $1", age) 

seems go interface isn't translating question marks numbered placeholders way many interfaces question mark getting way database , confusing everything.

you should able switch numbered placeholders instead of question marks:

 row := db.queryrow(     "select name users id = $1", id) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -