title: On conflict delete postgres
body: <p>I am trying to toggle a relation in a single query where it deletes the relation if it already exists, otherwise it creates it. I could add a third column with a bool that toggles it but I would rather delete it.</p>
  
  <p><strong>Schema</strong></p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS thread_subscription (
      profile_id     INTEGER REFERENCES profile (id),
      thread_id      INTEGER REFERENCES thread (id),
      UNIQUE(profile_id,thread_id)
  )
  </code></pre>
  
  <p><strong>Query</strong></p>
  
  <pre><code>INSERT INTO thread_subscription (profile_id,thread_id) 
  VALUES ($1,$2) ON CONFLICT (profile_id,thead_id) 
  DO DELETE FROM thread_subscription 
  WHERE profile_id = $1 AND thread_id = $2;
  </code></pre>