gpt4 book ai didi

postgresql - 添加 Postgres 约束时在 "user"处或附近出现语法错误

转载 作者:行者123 更新时间:2023-11-29 11:09:54 25 4
gpt4 key购买 nike

我正在运行 Postgres 8.4.13,并尝试向现有表添加约束。根据the docs ,这应该是可能的:

alter table indexed_friends add constraint no_duplicate_user_friends unique (user, friend);

然而,当我运行它时,出现以下错误:

ERROR:  syntax error at or near "user"

我很困惑,因为我几乎完全遵循文档中列出的唯一约束示例。我可以提供表架构,但由于它提示语法错误,我不确定是否有必要。

最佳答案

啊... user 是 Postgres 中的保留字。

用引号括起来:

alter table indexed_friends add constraint no_duplicate_user_friends unique ("user", friend);

成功了。

关于postgresql - 添加 Postgres 约束时在 "user"处或附近出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17266784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com