title: Using IF statement in PostgreSQL to update a column that can have only 2 values
body: <p>I have a table in PostgreSQL which has a column names &quot;value&quot; that can accept two string values (lets say &quot;one&quot; and &quot;two&quot;)
  I would like to create a query that updates a row and if value column is currently &quot;one&quot; it updates it to be &quot;two&quot; and vice-versa</p>
  <p>I've tried to the the following query:</p>
  <pre><code>IF EXISTS(SELECT * FROM table_name WHERE filename='file1' and value='one')
                        THEN UPDATE table_name SET value='two' WHERE filename='file1'
                        ELSE
                        UPDATE table_name SET value='one' WHERE filename='file1'
  end if; 
  </code></pre>
  <p>But I keep getting &quot;syntax error at or near &quot;IF&quot;&quot;</p>
  <p>Any help please?</p>