title: Can I run an SQL update statement using only dplyr syntax in R
body: <p>I need to update column values conditionnaly on other columns in some <code>PostgreSQL</code> database table. I managed to do it writing an SQL statement in R and executing it with <code>dbExecute</code> from <code>DBI</code> package.</p>
  
  <pre><code>library(dplyr)
  library(DBI)
  
  # Establish connection with database
  con &lt;- dbConnect(RPostgreSQL::PostgreSQL(), dbname = "myDb",
                   host="localhost", port= 5432, user="me",password = myPwd)
  
  # Write SQL update statement
  request &lt;- paste("UPDATE table_to_update",
                   "SET var_to_change = 'new value' ",
                   "WHERE filter_var = 'filter' ")
  
  # Back-end execution
  con %&gt;% dbExecute(request)
  </code></pre>
  
  <p>Is it possible to do so using only <code>dplyr</code> syntax ? I tried, out of curiosity,</p>
  
  <pre><code>con %&gt;% tbl("table_to_update") %&gt;%
     mutate(var_to_change = if (filter_var == 'filter') 'new value' else var_to_change)
  </code></pre>
  
  <p>which works in R but obviously does nothing in db since it uses a <code>select</code> statement. <code>copy_to</code> allows only for <code>append</code> and <code>overwite</code> options, so I can't see how to use it unless deleting then appending the filtered observations...</p>