postgresql Postgres 表列名限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10891368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres table column name restrictions?
提问by resting
I did this in psql:
我在 psql 中做了这个:
CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT, ip TEXT);
I get
我得到
ERROR: syntax error at or near "user" LINE 1: ...BLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT,...
I do:
我愿意:
CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, userd TEXT, ip TEXT);
It works.
Note the userd instead of user.
有用。
注意 userd 而不是 user。
Are there some restrictions on the column names that a table can have? (postgresql v9.1.3)
表可以具有的列名是否有一些限制?(postgresql v9.1.3)
回答by mechanical_meat
Here's a nice table of reserved words in PostgreSQL:
http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html
这是一个很好的 PostgreSQL 保留字表:http:
//www.postgresql.org/docs/current/static/sql-keywords-appendix.html
It is probably best to simply avoid using those words as table- or column-names.
An alternative, however, is to enclose the identifier in double-quotes, e.g.:
最好避免将这些词用作表名或列名。
但是,另一种方法是将标识符括在双引号中,例如:
CREATE TABLE IF NOT EXISTS apiss (
skey TEXT,
time INTEGER,
"user" TEXT,
ip TEXT);
回答by R13e
In my company, I had to scan an entire database for reserved words. I solved the task with the help of
在我的公司,我不得不扫描整个数据库以查找保留字。我在帮助下解决了这个任务
select * from pg_get_keywords()