天天看點

注意PostgreSQL的關鍵字(保留字)和identified的用法和位置

關鍵字即詞法解析時用到的一些固定的單詞,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位置時,還可能是定義名稱的位置。

例子

是以,如果你遇到類似的錯誤,用雙引号,或者換名字即可。

繼續閱讀