title: SELECTING multiple copies of some rows, single copies of others for INSERT
body: <p>In Postgres, I want to copy over rows from a table of templates into a table of instances. The trick is, I want to make multiple copies of some rows and only single copies of others.</p>
  <p>One example of syntax that isn't working:</p>
  <pre><code>INSERT INTO owned_instances
  (
    template_id,
    owner,
    property1,
    property2,
    etc
  )
  SELECT
    id,
    '478aa65e-ecf7-48fb-bc20-f7fcf300aaa9',
    property1,
    property2,
    etc
  FROM templates
  WHERE id IN (1, 1, 1, 2, 3);
  </code></pre>
  <p>The intent here would be that the owner would receive 3 copies of template 1, and 1 copy each of templates 2 and 3.</p>
  <p>This version doesn't work. <strong>WHERE id IN</strong> only grabs one copy of each listed <strong>id</strong>. Other syntaxes I've tried have been equally fruitless.</p>
  <p>Of course it's possible with multiple insert calls, but I have to wonder if there's a tidy &amp; efficient way to do this in a single insert.</p>
  <hr />
  <p>Attempting to anticipate one question:
  The copies in the table of instances will be individually mutated later. So the quick solve of just adding a column to count how many copies one row represents won't work in this case.</p>