Table defintion is
create table users (
serial_no integer PRIMARY KEY DEFAULT nextval('serial'),
uid bigint NOT NULL,
username varchar(32),
name text,
CONSTRAINT production UNIQUE(uid)
);
I used this query
INSERT INTO users (uid) values(123) ;
It says duplicate key value violates unique constraint. So I googled it and found this link
So I tried
INSERT INTO users (uid) values(123)
where 1 in (select 1 from users where uid = 123) ;
It says yntax error at or near “WHERE”.
How to use a statement of insert into using the where clause so that when I run the same query using php it does not return an error
column uid is unique
The INSERT statement doesn’t support a WHERE clause. Run this.
That will give you a syntax error because of the WHERE clause.
SELECT statements can have a WHERE clause, though. This will insert 2 into the test table one time. Run it as many times as you want; it won’t raise an error. (But it will insert only one row at the most.)
So your query, assuming you’re trying to avoid raising an error on a duplicate key, should be something like this.