Postgres丢失表格语法错误 [英] Postgres drop table syntax error

查看:374
本文介绍了Postgres丢失表格语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Postgres 9.3.2在heroku上。

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


推荐答案

用户是一个保留关键字在Postgres中。如果您想引用名为 user 的实际表:

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 TABLEuser;

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.

这篇关于Postgres丢失表格语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆