为什么不替换我的SQL占位符(使用Go pq)? [英] Why aren't my SQL placeholders being replaced (using Go pq)?
本文介绍了为什么不替换我的SQL占位符(使用Go pq)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据文档,我正在这样做
As per the docs, I'm doing this
var thingname string = "asdf";
var id int
err = database.QueryRow("SELECT id from things where thing = ?", thingname).Scan(&id)
但是Postgres在说
but Postgres is saying
ERROR: syntax error at end of input at character 41
STATEMENT: SELECT id from things where thing = ?
我看不出我在演示代码上做得有多大不同.我正在使用 pq .
I can't see that I'm doing much different to the demo code. I'm using pq.
推荐答案
确切的语法取决于数据库.
The exact syntax is database dependent.
使用
err = database.QueryRow("SELECT id from things where thing = $1", thingname).Scan(&id)
这篇关于为什么不替换我的SQL占位符(使用Go pq)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文