title: Postgres ERROR:duplicate key value violates unique constraint
body: <p>Table defintion is</p>
  
  <pre><code>create table users (
  serial_no integer PRIMARY KEY DEFAULT nextval('serial'),
  uid bigint NOT NULL,
  username varchar(32),
  name text,
  CONSTRAINT production UNIQUE(uid)
  );
  </code></pre>
  
  <p>I used this query</p>
  
  <pre><code>INSERT INTO users (uid) values(123) ;
  </code></pre>
  
  <p>It says duplicate key value violates unique constraint. So I googled it and found this <a href="https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-postgresql">link</a> </p>
  
  <p>So I tried </p>
  
  <pre><code>INSERT INTO users (uid) values(123) 
  where 1 in (select 1 from users where uid = 123) ;
  </code></pre>
  
  <p>It says yntax error at or near "WHERE". </p>
  
  <p>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</p>
  
  <p>column uid is unique</p>