title: Insert multiple rows where not exists PostgresQL
body: <p>I'd like to generate a single sql query to mass-insert a series of rows that don't exist on a table. My current setup makes a new query for each record insertion similar to the solution detailed in <a href="https://stackoverflow.com/questions/15840922/where-not-exists-in-postgresql-gives-syntax-error">WHERE NOT EXISTS in PostgreSQL gives syntax error</a>, but I'd like to move this to a single query to optimize performance since my current setup could generate several hundred queries at a time. Right now I'm trying something like the example I've added below:</p>
  
  <pre><code>INSERT INTO users (first_name, last_name, uid) 
  SELECT ( 'John', 'Doe', '3sldkjfksjd'), ( 'Jane', 'Doe', 'adslkejkdsjfds')
  WHERE NOT EXISTS (
    SELECT * FROM users WHERE uid IN ('3sldkjfksjd', 'adslkejkdsjfds')
  )
  </code></pre>
  
  <p>Postgres returns the following error:</p>
  
  <pre><code>PG::Error: ERROR:  INSERT has more target columns than expressions
  </code></pre>
  
  <p>The problem is that PostgresQL doesn't seem to want to take a series of values when using SELECT. Conversely, I can make the insertions using VALUES, but I can't then prevent duplicates from being generated using WHERE NOT EXISTS.</p>
  
  <p><a href="http://www.techonthenet.com/postgresql/insert.php" rel="noreferrer">http://www.techonthenet.com/postgresql/insert.php</a> suggests in the section EXAMPLE - USING SUB-SELECT that multiple records <em>should</em> be insertable from another referenced table using SELECT, so I'm wondering why I can't seem to pass in a series of values to insert. The values I'm passing are coming from an external API, so I need to generate the values to insert by hand.</p>