postgresql 添加 Postgres 约束时“用户”处或附近的语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17266784/
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
Syntax error at or near "user" when adding Postgres constraint
提问by Kevin Burke
I'm running Postgres 8.4.13, and trying to add a constraint to an existing table. According to the docs, this should be possible:
我正在运行 Postgres 8.4.13,并尝试向现有表添加约束。根据文档,这应该是可能的:
alter table indexed_friends add constraint no_duplicate_user_friends unique (user, friend);
Yet when I run this I get the following error:
然而,当我运行它时,我收到以下错误:
ERROR: syntax error at or near "user"
I'm confused because I'm following an unique constraint example listed in the documentation almost exactly. I can provide the table schema, but since it's complaining about a syntax error, I'm not sure that's necessary.
我很困惑,因为我几乎完全按照文档中列出的唯一约束示例进行操作。我可以提供表模式,但由于它抱怨语法错误,我不确定这是否必要。
回答by Kevin Burke
Ahhh... The word user
is a reserved word in Postgres.
啊…… 这个user
词在 Postgres 中是保留字。
Surrounding it in quotes:
用引号包围它:
alter table indexed_friends add constraint no_duplicate_user_friends unique ("user", friend);
worked.
工作。