title: Updating key constraints on multiple records simultaneously
body: <p>We have a table with a unique key which gets updated by ‘aging’ older records, as mentioned by @Tony O’Hagan <a href="https://stackoverflow.com/a/50558416">here</a>.</p>
  <p>The table looks as follows:</p>
  <pre><code>-- auto-generated definition
  create table abc
  (
      key   uuid    not null,
      hash  text    not null,
      age   integer not null,
      value varchar(50),
      constraint abc_pkey
          primary key (key, age)
  );
  </code></pre>
  <p>We can simulate an ‘aged’ record with the following dummy data:</p>
  <pre><code>INSERT INTO public.abc (key, hash, age, value) VALUES ('bec619bb-451c-49d8-b555-4d16e1f724fb', 'asdf', 0, '1');
  INSERT INTO public.abc (key, hash, age, value) VALUES ('bec619bb-451c-49d8-b555-4d16e1f724fb', 'asdf', 1, '2');
  INSERT INTO public.abc (key, hash, age, value) VALUES ('bec619bb-451c-49d8-b555-4d16e1f724fb', 'asdf', 2, '3');
  </code></pre>
  <p>When I want to add a new record, I must first ‘age’ the older records before inserting a new record with age=0</p>
  <p>However I get the following error message when I run the query below:</p>
  <pre><code>[23505] ERROR: duplicate key value violates unique constraint &quot;abc_pkey&quot; Detail: Key (key, age)=(bec619bb-451c-49d8-b555-4d16e1f724fb, 2) already exists.
  
  UPDATE abc
  SET age = age +1
  WHERE key IN (
      'bec619bb-451c-49d8-b555-4d16e1f724fb'
      )
  </code></pre>
  <p>How can I update/age these records?</p>