根据文档,我正在这样做
var thingname string = "asdf";
var id int
err = database.QueryRow("SELECT id from things where thing = ?", thingname).Scan(&id)
但是 Postgres 说
ERROR: syntax error at end of input at character 41
STATEMENT: SELECT id from things where thing = ?
我看不出我所做的与演示代码有多大不同。我正在使用 pq .
最佳答案
确切的语法取决于数据库。
使用
err = database.QueryRow("SELECT id from things where thing = $1", thingname).Scan(&id)
关于sql - 为什么我的 SQL 占位符没有被替换(使用 Go pq)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18577855/