PostgreSQL 语法错误 eof 导致提交
我们正在努力将各个文件合并到一个 PostgreSQL 数据库组中。这些文件本身都运行得很好,当我们合并时,我们可以毫无问题地运行它们。它开始挂在一个触发器的创建上,因此我们注释掉了该触发器。下次运行合并文件时,我们收到以下错误:
ERROR: Syntax error at end of input
LINE 181: --$$ LANGUAGE plpgsql
在此错误之后,出现了后续语法错误,然后令我们恐惧的是,我们在日志文件中发现了以下内容:
ERROR: Syntax error at end of input
LINE 181: --$$ LANGUAGE plpgsql
COMMIT
我们在此文件中进行了测试,其中包含不应该的测试数据被输入到数据库中,谁知道我们数据库中有多少数据被破坏。我们已经检查了包含的每个文件,并且任何地方都没有 COMMIT
!
有人遇到过类似的事情吗?解析错误是否会导致提交?
We are working on merging individual files into a group PostgreSQL database. The files have all been working perfectly fine on their own and when we have combined we have run them with no problems. It started to hang on the creation of one trigger, so we commented the trigger out. The next time we ran the merge file we got the following error:
ERROR: Syntax error at end of input
LINE 181: --$ LANGUAGE plpgsql
Following this error there were subsequent syntax errors and then to our horror we found the following in our log file:
ERROR: Syntax error at end of input
LINE 181: --$ LANGUAGE plpgsql
COMMIT
We had tests in this file that contained test data that was NOT supposed to be entered into the database, corrupting who knows how much of the data in our database. We have looked through every file included and there is no COMMIT
anywhere!
Has anyone ever run into something similar? Is there any reason why an error in parsing would ever cause a commit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有
BEGIN
语句,则 PostgreSQL 连接处于“自动提交”模式,在语句运行后提交每个更改。由于您错误地注释了代码,我想说您已经在代码前面注释了BEGIN
语句。但我不能确定,因为你没有提供任何 SQL。请注意,语法:
不会注释掉函数
$$
的结尾。它的意思是空注释作为字符串中的最后一个内容。如果您将该行读为:这可能会对您有所帮助:这就是为什么您在“注释”行上收到解析错误的原因。如果它确实被注释了,PostgreSQL将不会解析它。
$$
是一个包含 SQL 代码的引号运算符,并且只是一种反对使用'
进行引用的便捷语法(这意味着您必须对内部的每个引号进行双引号)引用的 SQL)。您认为注释掉的行实际上只是以两个连字符结尾的字符串的一部分。一般注意事项:您应该仅使用注释来向代码添加描述,而不是禁用代码部分。如果您需要访问旧版本的代码,请使用版本控制。
编辑:对带引号的字符串进行澄清解释。希望现在这更有意义。
If you don't have a
BEGIN
statement, then the PostgreSQL connection is in "autocommit" mode, committing each change after the statement is run. Since you're incorrectly commenting your code, I'd say you've commented theBEGIN
statement earlier in the code. But I can't be sure because you did not provide any of your SQL.Note that the syntax:
does not comment out the end of function
$$
. What it means is empty comment as the last thing inside a string. It might help you if you read the line as:That is why you're getting a parse error on a "commented" line. If it was actually commented, PostgreSQL would not parse it.
$$
is a quote operator enclosing SQL code, and is just a convenience syntax against using'
's for quoting (which would mean you have to double-quote each quote inside the quoted SQL). What you think was a commented out line was actually just a piece of a string ending with two hyphens.On a general note: You should use commenting only for adding descriptions to the code and not disabling sections of code. Use version control if you need to have access to older versions of the code.
Edit: Clarified explanation on quoted strings. Hope this makes more sense now.