在“用户”处或附近的语法错误。添加Postgres约束时 [英] Syntax error at or near "user" when adding Postgres constraint
本文介绍了在“用户”处或附近的语法错误。添加Postgres约束时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行Postgres 8.4.13,并尝试向现有表中添加约束。根据文档,这应该是可能的:
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:
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.
推荐答案
啊... user
是Postgres中的保留字。
Ahhh... The word user
is a reserved word in Postgres.
将其用引号引起来:
alter table indexed_friends add constraint no_duplicate_user_friends unique ("user", friend);
有效。
这篇关于在“用户”处或附近的语法错误。添加Postgres约束时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文