title: How to include excluded rows in RETURNING from INSERT ... ON CONFLICT
body: <p>I've got this table (generated by Django):</p>
  
  <pre><code>CREATE TABLE feeds_person (
    id serial PRIMARY KEY,
    created timestamp with time zone NOT NULL,
    modified timestamp with time zone NOT NULL,
    name character varying(4000) NOT NULL,
    url character varying(1000) NOT NULL,
    email character varying(254) NOT NULL,
    CONSTRAINT feeds_person_name_ad8c7469_uniq UNIQUE (name, url, email)
  );
  </code></pre>
  
  <p>I'm trying to bulk insert a lot of data using <code>INSERT</code> with an <code>ON CONFLICT</code> clause.</p>
  
  <p>The wrinkle is that I need to get the <code>id</code> back for <em>all</em> of the rows, whether they're already existing or not.</p>
  
  <p>In other cases, I would do something like:</p>
  
  <pre><code>INSERT INTO feeds_person (created, modified, name, url, email)
  VALUES blah blah blah
  ON CONFLICT (name, url, email) DO UPDATE SET url = feeds_person.url
  RETURNING id
  </code></pre>
  
  <p>Doing the <code>UPDATE</code> causes the statement to return the <code>id</code> of that row. Except, it doesn't work with this table. I <em>think</em> it doesn't work because I've got multiple fields unique together whereas in other instances I've used this method I've had just one unique field.</p>
  
  <p>I get this error when trying to run the SQL through Django's cursor:</p>
  
  <blockquote>
  <pre><code>django.db.utils.ProgrammingError: ON CONFLICT DO UPDATE command cannot affect row a second time
  HINT:  Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
  </code></pre>
  </blockquote>
  
  <p>How do I do the bulk insert with this table and get back the inserted and existing ids?</p>