当试图使用该WHERE NOT EXISTS
子句来防止在列中添加具有重复值的行时age
,我得到了错误syntax error at or near "WHERE"
。
为什么会抛出语法错误?我正在使用 Postgresql 9.1。
SQL
INSERT INTO live.users ("website", "age")
values ('abc', '123')
WHERE NOT EXISTS (SELECT age FROM live.users WHERE age = 123);
错误
ERROR: syntax error at or near "WHERE"
LINE 6: WHERE NOT EXISTS (SELECT age FROM live.users W...