title: Stored Procedure with if else statement in PostgreSQL
body: <p>I'm trying to find the best way to make a 'like' button on my application. I would like to hit the same endpoint and have a stored procedure take care of the logic. This is what I have so far, but it doesn't seem to work. My goal is to test if a record exist, if it does then delete the record, else  create the record. Please let me know what I'm doing wrong, or if a stored procedure is the way to go here. Below is the logic that I want in the procedure, but currently not working. Thanks</p>
  <pre><code>IF (SELECT * FROM favorite_movies WHERE movie_id = '577922' and user_id = '5' limit 1)then
   delete from favorite_movies WHERE movie_id = 577922 and user_id = 5;
    else 
    INSERT INTO favorite_movies (user_id, movie_id)VALUES (5, 577922);
  END IF
  </code></pre>
  <p>The error I'm getting is</p>
  <pre><code>SQL Error [42601]: ERROR: syntax error at or near &quot;IF&quot;
    Position: 1
  </code></pre>