title: Node-postgres parameterized query for INSERT INTO if not exists
body: <p>I have a working parameterized query for an insert statement but I now want to add in a 'WHERE NOT EXISTS' clause. The working insert looks like this:</p>
  
  <pre><code>pgClient.query("INSERT INTO social_posts (username, user_image, message, image_url, post_id, post_url, location, network) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)", postArray, 
      function(err, result) {...}
  </code></pre>
  
  <p>What I'd like to implement is:</p>
  
  <pre><code>pgClient.query("INSERT INTO social_posts(username, user_image, message, image_url, post_id, post_url, location, network) SELECT ($1,$2,$3,$4,$5,$6,$7,$8) WHERE NOT EXISTS (SELECT 1 FROM social_posts WHERE post_id = $9)", postArray,
      function(err, result) {...}
  </code></pre>
  
  <p>In this case the $9 would actually be equal to postArray[4]. </p>
  
  <p>I've tried pushing the value into the array again, that didn't work:</p>
  
  <pre><code>error running query { [error: operator does not exist: character varying = bigint]
  name: 'error',
  length: 207,
  severity: 'ERROR',
  code: '42883',
  detail: undefined,
  hint: 'No operator matches the given name and argument type(s). You might need to add explicit type casts.',
  position: '198',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_oper.c',
  line: '722',
  routine: 'op_error' }
  </code></pre>
  
  <p>I tried interpolating the value, that didn't work:</p>
  
  <pre><code>error running query { [error: there is no parameter $1]
  name: 'error',
  length: 88,
  severity: 'ERROR',
  code: '42P02',
  detail: undefined,
  hint: undefined,
  position: '114',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'parse_expr.c',
  line: '823',
  routine: 'transformParamRef' }
  </code></pre>
  
  <p>Does anyone have any ideas? Thanks in advance!</p>