title: Postgres skip update if NEW equals OLD without triggers
body: <p>Let's say I have a table I need to update with a mixture of new, changed and unchanged existing data (for legacy reasons we cannot separate them into 3 different calls).</p>
  <p>The minimal example table is this:</p>
  <pre><code>(
      id        integer,
      name      text
          constraint name_unique
              unique,
      metadata  jsonb,
      version   integer default 0
  );
  </code></pre>
  <p>There are 3 different things that need to happen:</p>
  <ol>
  <li>Insert the new values if <code>name</code> is not there (<code>INSERT ... ON CONFLICT (name) ...</code>)</li>
  <li>Update <code>metadata</code> and bump <code>version</code> with <code>1</code> if <code>name</code> is already there and <code>OLD.metadata &lt;&gt; NEW.metadata</code> &lt;- this is the one I cannot write down with the <code>ON CONFLICT</code> syntax as it only(?) gives me access to <code>NEW</code> value as <code>EXCLUDED</code> but not the value at hand in <code>ROW</code>.</li>
  <li>Skip update and version bump if <code>OLD.metadata = NEW.metadata</code></li>
  </ol>
  <p>My current best guess was casting <code>jsonb</code> to plain text and see if the two was the same, but I could not figure out if it was possible to do it without having to write a <code>FUNCTION</code> and a <code>TRIGGER</code>.</p>
  <p><strong>Can these 3 things performed in one query?</strong></p>