When trying to use the WHERE NOT EXISTS
clause to prevent adding a row with a duplicate value in the column age
, I get the error syntax error at or near "WHERE"
.
Why did it throw a syntax error? I'm using 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
ERROR: syntax error at or near "WHERE"
LINE 6: WHERE NOT EXISTS (SELECT age FROM live.users W...