title: How to conditionally update multiple rows using knex with postgresql?
body: <p>Here is an example of the table layout;</p>
  
  <pre><code>CREATE TABLE test (id1 int, id2 int, auth boolean);
  INSERT INTO test VALUES (1, 1, true);
  </code></pre>
  
  <p>I'm trying to convert the following query into the knex.js framework;</p>
  
  <pre><code>UPDATE test as t 
      SET auth = c.auth
      from (values (1, 1, false),(2, 1, false))
      as c(id1, id2, auth)
      where c.id1 = t.id1 AND c.id2 = t.id2;
  
  select * from test
  </code></pre>
  
  <p>Here is a fiddle: <a href="http://sqlfiddle.com/#!17/62529/8" rel="nofollow noreferrer">http://sqlfiddle.com/#!17/62529/8</a></p>
  
  <p>I've looked around, and found the following resources: <a href="https://github.com/tgriesser/knex/issues/556" rel="nofollow noreferrer">github issue</a>, <a href="https://stackoverflow.com/questions/40543668/batch-update-in-knex/40555000">update multiple queries (no conditional)</a></p>
  
  <p>After trying to implement these methods, I'm still coming up unsuccessful and not sure where I'm going wrong.</p>
  
  <p>I've tried to brute force the query by wrapping my original postgres query into a knex.raw statement, like: </p>
  
  <pre><code>return knex.raw('' +
      'UPDATE test as t ' +
      'SET auth = c.auth ' +
      'from (values (1, 1, false),(2, 1, false))' +
      'as c(id1, id2, auth)' +
      'where c.id1 = t.id1 AND c.id2 = t.id2;')
  </code></pre>
  
  <p>which comes up with the error <code>syntax error on or near « as »</code></p>
  
  <p>I've also tried to follow the github issue advice by using;</p>
  
  <pre><code> let string = knex
          .into('test t')
          .update('auth, c.auth')
          .values('(1, 1, false), (2, 1, false)')
          .where(knex.raw('c.id1 = t.id1 AND c.id2 = t.id2'))
          .toString()
  
          knex.raw(string)
  </code></pre>
  
  <p>which returns the error 'values' is not a function.</p>
  
  <p>I am new to both knex and postgres, so I'm not sure if I'm missing something painfully obvious! Any help is much appreciated.</p>