gpt4 book ai didi

sql - Postgres 删除表语法错误

转载 作者:行者123 更新时间:2023-11-29 11:09:57 25 4
gpt4 key购买 nike

heroku 上的 Postgres 9.3.2。

很确定我只是个白痴,但我似乎无法弄清楚为什么我的语法是错误的。

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

最佳答案

用户reserved keyword在 Postgres 中。如果你想引用名为 user实际表,你必须将它放在引号中:

DROP TABLE "用户";

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

关于sql - Postgres 删除表语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21051521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com