无法在 PostgreSQL 中创建名为“user"的数据库表

编程入门 行业动态 更新时间:2024-10-25 21:27:05
本文介绍了无法在 PostgreSQL 中创建名为“user"的数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

似乎 PostgreSQL 不允许创建名为 'user' 的数据库表.但是 MySQL 允许创建这样的表.

It seems PostgreSQL does not allow to create a database table named 'user'. But MySQL will allow to create such a table.

是因为它是一个关键词吗?但是 Hibernate 无法识别任何问题(即使我们设置了 PostgreSQLDialect).

Is that because it is a key word? But Hibernate cannot identify any issue (even if we set the PostgreSQLDialect).

推荐答案

user 是一个保留字,将保留字用于标识符(表、列)通常不是一个好主意.

user is a reserved word and it's usually not a good idea use reserved words for identifiers (tables, columns).

如果你坚持这样做,你必须把表名放在双引号中:

If you insist on doing that you have to put the table name in double quotes:

create table "user" (...);

但是您在引用表格时总是需要使用双引号.此外,表名是区分大小写的."user" 与 "User" 是不同的表名.

But then you always need to use double quotes when referencing the table. Additionally the table name is then case-sensitive. "user" is a different table name than "User".

如果您想省去很多麻烦,请使用不同的名称.用户、user_account、...

If you want to save yourself a lot of trouble use a different name. users, user_account, ...

有关引用标识符的更多详细信息可以在手册中找到:www.postgresql/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

More details on quoted identifiers can be found in the manual: www.postgresql/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

更多推荐

无法在 PostgreSQL 中创建名为“user"的数据库表

本文发布于:2023-10-14 12:09:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1491025.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   PostgreSQL   user   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!