Postgres:Table 使用 \d 显示,但在删除 table 时显示语法错误

Postgres: Table is shown using \d but shows syntax error while dropping the table

我做的时候遇到了奇怪的问题

`temp=# \d
                      List of relations
Schema |             Name              |   Type   |      Owner      
--------+-------------------------------+----------+-----------------
public | ORDER                         | table    | admin
public | ORDER_id_seq                  | sequence | admin `  

如上图table列表。 table 名称 ORDER 即将出现,但是当我尝试删除它时,出现语法错误
temp=# drop table ORDER; ERROR: syntax error at or near "ORDER" LINE 1: drop table ORDER;

有什么问题,还有什么其他方法可以删除 ORDER table?

ORDER 是保留关键字,如以下内容所述: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html

所以作为对象名需要用双引号括起来。此外,由于它是大写的,即使它不是关键字,这些双引号也是必需的。

就这样:

drop table "ORDER";

由于 ORDER 也是 SQL "reserved word",因此您必须将 table 名称放在双引号中。 (无论如何你都必须这样做,因为它是大写的)