bmizerany / pq

MIT License
181 stars 30 forks source link

Suggestion: document how to use bind parameters #7

Closed emicklei closed 10 years ago

emicklei commented 11 years ago

Unlike is documented on http://golang.org/pkg/database/sql/#example_DB_Query, this driver cannot handle the "?" placeholder for query parameters. Instead the $ notation must be used. Figuring this out took me far too long while staring at:

SELECT * FROM questions WHERE id=?

pq: S:"ERROR" C:"42883" M:"operator does not exist: integer =?" H:"No operator matches the given name and argument type(s). You might need to add explicit type casts." P:"33" F:"parse_oper.c" L:"755" R:"op_error"

Eventually, I found the correct expression:

db.Query("SELECT * FROM questions WHERE id=$1", 1)

natefinch commented 11 years ago

I agree with this. I had the same problem, and from the stack overflow posts, this is a common problem.

wilig commented 11 years ago

Agreed, this cost me 30 minutes of googling.

bmizerany commented 10 years ago

Closing. Please re-post at http://github.com/lib/pq if there is still a problem.

farhansyed77 commented 8 years ago

@wilig - 30 minutes of googling me too.