4

根据文档,我正在这样做

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

4

2 回答 2

4

确切的语法取决于数据库。

利用

err = database.QueryRow("SELECT id from things where thing = $1", thingname).Scan(&id)
于 2013-09-02T17:01:14.273 回答
2

尝试使用$1而不是?:-

err = database.QueryRow("SELECT id from things where thing = $1", thingname).Scan(&id)
于 2013-09-02T17:01:35.480 回答