Postgres表的列名有限制吗? [英] Postgres table column name restrictions?
本文介绍了Postgres表的列名有限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是在psql中完成的:
I did this in psql:
CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT, ip TEXT);
我知道了
ERROR: syntax error at or near "user" LINE 1: ...BLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, user TEXT,...
我这样做:
CREATE TABLE IF NOT EXISTS apiss (skey TEXT, time INTEGER, userd TEXT, ip TEXT);
它有效。
注意用户而不是用户。
It works.
Note the userd instead of user.
表可以具有的列名是否有一些限制?
(PostgreSQL v9.1.3)
Are there some restrictions on the column names that a table can have? (postgresql v9.1.3)
推荐答案
在PostgreSQL中,这是一个很好的保留字表:
http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html
Here's a nice table of reserved words in 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);
这篇关于Postgres表的列名有限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文