问题描述
我已经在MySQL和PostgreSQL中使用了下一条SQL语句,但是在PostgreSQL中失败了。
db.Query(` SELECT COUNT(*)as N FROM email WHERE address =?`,email)
pq:F:scan.lM:输入结束时的语法错误S:错误C: 42601P:50R:scanner_yyerrorL:993
什么问题? PostgreSQL中的错误信息是非常神秘的。
你没有提供任何有关语言/环境的细节,无论如何,我都会猜测:
MySQL的准备语句原生使用?
作为参数占位符,但PostgreSQL使用 $ 1
, $ 2
尝试用<$替换?
c $ c> $ 1 并查看它是否有效:
WHERE地址= $ 1
一般而言,Postgres错误信息非常明确,但在这种情况下,您已经设法将解析器混淆到了理智之外。 :)
I have used the next SQL statement in both MySQL and PostgreSQL, but it fails in PostgreSQL
db.Query(`SELECT COUNT(*) as N FROM email WHERE address = ?`, email)
with this error:
pq: F:"scan.l" M:"syntax error at end of input" S:"ERROR" C:"42601" P:"50" R:"scanner_yyerror" L:"993"
What's the problem? The error messages in PostgreSQL are very cryptic.
You haven't provided any details about the language/environment, but I'll try a wild guess anyway:
MySQL's prepared statements natively use ?
as the parameter placeholder, but PostgreSQL uses $1
, $2
etc. Try replacing the ?
with $1
and see if it works:
WHERE address = $1
In general, Postgres error messages are very clear, but in this instance you've managed to confuse the parser beyond sanity. :)
这篇关于PostgreSQL中输入结束时的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!