无法在PostgreSQL中创建名为'user'的数据库表 [英] Cannot create a database table named 'user' in PostgreSQL

查看:531
本文介绍了无法在PostgreSQL中创建名为'user'的数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来PostgreSQL不允许创建一个名为'user'的数据库表。但是MySQL将允许创建这样的表。



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

user 是一个保留字,它通常不是一个好主意,使用标识符(表,列)的保留字。



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

  create tableuser(...); 

但是,总是在引用表时需要使用双引号。此外,表名称区分大小写。 user是不同于User的表名。



如果您想为自己节省很多麻烦,请使用不同的名称。 用户 user_account ,...



更多资讯关于引用的标识符可以在手册中找到: http:// www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS


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

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

解决方案

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" (...);

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".

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

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

这篇关于无法在PostgreSQL中创建名为'user'的数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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