The INSERT statement does not support the WHERE clause. Run it.
create table test ( n integer primary key ); insert into test values (1); insert into test values (2) where true;
This will give you a syntax error due to the WHERE clause.
SELECT statements may have a WHERE clause. This will insert 2 into the test pattern once. Run it as many times as you want; this will not cause an error. (But it will only insert one maximum row.)
insert into test (n) select 2 where 2 not in (select n from test where n = 2);
Thus, your request, assuming that you are trying to avoid increasing the error by a duplicate key, should be something like this.
INSERT INTO users (uid) SELECT 123 WHERE 123 not in (SELECT uid FROM users WHERE uid = 123) ;
source share