我在MySQL和PostgreSQL中都使用了下一条SQL语句,但是在PostgreSQL中却失败了
db.Query(`SELECT COUNT(*) as N FROM email WHERE address = ?`, email)
出现此错误:
pq: F:"scan.l" M:"syntax error at end of input" S:"ERROR" C:"42601" P:"50" R:"scanner_yyerror" L:"993"
有什么问题? PostgreSQL 中的错误消息非常含糊。
原文由 user1243746 发布,翻译遵循 CC BY-SA 4.0 许可协议
您没有提供有关语言/环境的任何详细信息,但无论如何我都会尝试大胆猜测:
MySQL’s prepared statements natively use
?
as the parameter placeholder, but PostgreSQL uses$1
,$2
etc. Try replacing the?
with$1
看看它是否有效:总的来说,我发现 Postgres 错误消息比竞争产品(咳咳,MySQL, 尤其是 Oracle)更好,但在这种情况下,你已经设法混淆了解析器,超出了理智。 :)