关键字即词法解析时用到的一些固定的单词,identifier则是用户定义的一些名词(如表名,索引名,字段名,函数名等等)
postgresql 有一张关键字列表
<a href="https://www.postgresql.org/docs/9.5/static/sql-keywords-appendix.html">https://www.postgresql.org/docs/9.5/static/sql-keywords-appendix.html</a>
在这个列表中的关键字,如果出现的位置可以是identified,则会报错。
<a href="https://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#sql-syntax-identifiers">https://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#sql-syntax-identifiers</a>
例子:
and就是一个关键字,并且他出现在了可以是identifer的位置,所以要解决这个问题就是加双引号,或者排除歧义。
使用双引号引排除歧义,把它变成别名identifier。
使用as改变词法,排除歧义,把它变成别名。
还有,如果key words出现在identifier位置时,还可能是定义名称的位置。
例子
所以,如果你遇到类似的错误,用双引号,或者换名字即可。