Pradeep Kr Kaushal
Pradeep Kr Kaushal

Reputation: 1546

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

I have weird issue when I do

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

As the table list as shown above. The table name ORDER is coming but when I try to drop it, I get the syntax error as
temp=# drop table ORDER; ERROR: syntax error at or near "ORDER" LINE 1: drop table ORDER;

What is the issue and what is other way to drop ORDER table?

Upvotes: 1

Views: 172

Answers (2)

jjanes
jjanes

Reputation: 44137

Since ORDER is also a SQL "reserved word", you have to put the table name in double quotes. (Which you have to do anyway because it is capitalized)

Upvotes: 1

Daniel Vérité
Daniel Vérité

Reputation: 61516

ORDER is a reserved keyword as mentioned in: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html

So it needs to be enclosed in double quotes when used as an object name. Besides, as it's in uppercase, even if it wasn't a keyword these double quotes would be needed anyway.

Just do:

drop table "ORDER";

Upvotes: 3

Related Questions