32

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.

4

1 回答 1

61

啊……这个词user是 Postgres 中的保留字。

用引号括起来:

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

工作。

于 2013-06-24T01:03:24.693 回答