PostgreSQL中输入结束时的语法错误

时间:2021-09-16 22:54:02

I have used the next SQL statement in both MySQL and PostgreSQL, but it fails in PostgreSQL

我在MySQL和PostgreSQL中都使用了下一个SQL语句,但它在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.

有什么问题? PostgreSQL中的错误消息非常神秘。

3 个解决方案

#1


33  

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:

MySQL的准备语句本身使用?作为参数占位符,但PostgreSQL使用$ 1,$ 2等尝试替换? 1美元,看它是否有效:

WHERE address = $1

The error messages in PostgreSQL are very cryptic.

PostgreSQL中的错误消息非常神秘。

In general, I've found that Postgres error messages are better than competing products (ahem, MySQL and especially Oracle), but in this instance you've managed to confuse the parser beyond sanity. :)

总的来说,我发现Postgres错误消息比竞争产品(ahem,MySQL,尤其是Oracle)更好,但在这种情况下,你设法将解析器混淆得超出了理智。 :)

#2


7  

You are using Go right?

你正在使用Go吗?

try:

尝试:

db.Query(`SELECT COUNT(*) as N FROM email WHERE address = $1`, email)

#3


-1  

Try With @ Symbol Its Working for me.

尝试用@ Symbol为我工作。

when using ? Symbol:

什么时候用?符号:

it says "ERROR: 42601: syntax error at end of input"

它说“错误:42601:输入结束时的语法错误”

when Using $1:

使用$ 1时:

It says "ERROR: 42P02: there is no parameter $1"

它说“ERROR:42P02:没有参数$ 1”

#1


33  

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:

MySQL的准备语句本身使用?作为参数占位符,但PostgreSQL使用$ 1,$ 2等尝试替换? 1美元,看它是否有效:

WHERE address = $1

The error messages in PostgreSQL are very cryptic.

PostgreSQL中的错误消息非常神秘。

In general, I've found that Postgres error messages are better than competing products (ahem, MySQL and especially Oracle), but in this instance you've managed to confuse the parser beyond sanity. :)

总的来说,我发现Postgres错误消息比竞争产品(ahem,MySQL,尤其是Oracle)更好,但在这种情况下,你设法将解析器混淆得超出了理智。 :)

#2


7  

You are using Go right?

你正在使用Go吗?

try:

尝试:

db.Query(`SELECT COUNT(*) as N FROM email WHERE address = $1`, email)

#3


-1  

Try With @ Symbol Its Working for me.

尝试用@ Symbol为我工作。

when using ? Symbol:

什么时候用?符号:

it says "ERROR: 42601: syntax error at end of input"

它说“错误:42601:输入结束时的语法错误”

when Using $1:

使用$ 1时:

It says "ERROR: 42P02: there is no parameter $1"

它说“ERROR:42P02:没有参数$ 1”