Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Postgres 9.3.2 on heroku.

Pretty sure I'm just being an idiot, but I can't seem to figure out why my syntax is wrong.

db=> dt
              List of relations
 Schema |    Name    | Type  |     Owner      
--------+------------+-------+----------------
 public | device     | table | admin
 public | post       | table | admin
 public | user       | table | admin
(3 rows)

// why does this fail?
db=> drop table user; 
ERROR:  syntax error at or near "user"
LINE 1: drop table user;

// does the right thing
db=> drop table error; 
ERROR:  table "error" does not exist
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

User is a reserved keyword in Postgres. You'll have to put it in quotes if you want to refer to an actual table named user:

DROP TABLE "user";

Probably best to stay away from using reserved keywords as table names if you can help it. It usually ends up creating weird problems down the road. Users might be a better name for a table.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...