有没有办法让 Postgres 告诉你语法错误是什么 at/near?
Is there a way to have Postgres tell you what a syntax error was in addition to what it is at/near?
我已经尝试在 postgresql.conf 中将 'log_min_error_statement' 设置为 debug5,但我仍然在控制台和 postgresql 日志中收到标准的 "PostgreSQL said: syntax error at or near "AS"" 错误消息.
如果 PostgreSQL 知道错误是什么,它会告诉您,至少在大多数情况下是这样。
如果它只是说"Syntax error at or near ..."它不知道你的意思,也猜不出哪里出了问题。这是一个解析错误。它可以提供一个(很长的)建议列表,但这会使错误消息冗长得荒谬,例如:
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
是的,这是一个语法错误,因为它在任何层面上都没有意义。它出什么问题了?你如何简洁地描述它?解析器如何判断错误?
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
HINT: typo?
HINT: Did you use a reserved keyword as an identifier without "quoting" it? Like "AS"?
HINT: Did you leave out the value before the AS keyword?
HINT: ... endless possibilities ...
有时解析器会猜出您可能做错了什么。 PostgreSQL 的解析器会尝试在可以时告诉您,例如
psql -c "SELECT 'openquote";
ERROR: unterminated quoted string at or near "'openquote"
LINE 1: SELECT 'openquote
我已经尝试在 postgresql.conf 中将 'log_min_error_statement' 设置为 debug5,但我仍然在控制台和 postgresql 日志中收到标准的 "PostgreSQL said: syntax error at or near "AS"" 错误消息.
如果 PostgreSQL 知道错误是什么,它会告诉您,至少在大多数情况下是这样。
如果它只是说"Syntax error at or near ..."它不知道你的意思,也猜不出哪里出了问题。这是一个解析错误。它可以提供一个(很长的)建议列表,但这会使错误消息冗长得荒谬,例如:
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
是的,这是一个语法错误,因为它在任何层面上都没有意义。它出什么问题了?你如何简洁地描述它?解析器如何判断错误?
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
HINT: typo?
HINT: Did you use a reserved keyword as an identifier without "quoting" it? Like "AS"?
HINT: Did you leave out the value before the AS keyword?
HINT: ... endless possibilities ...
有时解析器会猜出您可能做错了什么。 PostgreSQL 的解析器会尝试在可以时告诉您,例如
psql -c "SELECT 'openquote";
ERROR: unterminated quoted string at or near "'openquote"
LINE 1: SELECT 'openquote