本文介绍了PostgreSQL 输入结束时的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MySQL 和 PostgreSQL 中都使用了下一条 SQL 语句,但在 PostgreSQL 中失败

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

出现此错误:

pq: F:"scan.l" M:"输入结束时的语法错误" S:"ERROR" C:"42601" P:"50" R:"scanner_yyerror" L:"993"

有什么问题吗?PostgreSQL 中的错误信息非常神秘.

解决方案

您还没有提供有关语言/环境的任何详细信息,但我还是会尝试胡乱猜测:

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

WHERE 地址 = $1

PostgreSQL 中的错误信息非常神秘.

总的来说,我发现 Postgres 错误消息比竞争产品(嗯,MySQL 和特别是 Oracle)要好,但是在这种情况下,您已经设法使解析器变得异常混乱.:)

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, 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. :)

这篇关于PostgreSQL 输入结束时的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 20:14
查看更多