Postgres 删除表语法错误 [英] Postgres drop table syntax error

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

问题描述

在 Heroku 上使用 Postgres 9.3.2.

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

推荐答案

User 是一个 保留关键字 在 Postgres 中.如果要引用名为 useractual 表,则必须将其放在引号中:

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:

删除表用户";

如果可以的话,最好不要使用保留关键字作为表名.它通常最终会产生奇怪的问题.Users 可能是一个更好的表名称.

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天全站免登陆