title: Insert to table from set returning function with parameters
body: <p>This is probably something simple but couldn't figure it out.</p>
  
  <p>I've table Summary and function <code>GetSummary</code> that returns row as set of Summary.  I can query it like this</p>
  
  <pre><code>SELECT GetSummary(arg1, arg2)
  GetSummary
  -----------
  (val1, val2, val3)
  </code></pre>
  
  <p>And like this that returns the actual columns:</p>
  
  <pre><code>SELECT * FROM GetSummary(arg1, arg2)
  col1  |   col2   | col3
  ------------------------
  val1  |   val2   | val3
  </code></pre>
  
  <p>Insertion to Summary works fine:</p>
  
  <pre><code>INSERT INTO Summary (SELECT * FROM GetSummary(arg1, arg2));
  INSERT 0 1
  </code></pre>
  
  <p>But I can't figure out how to insert several rows at once based on columns in other table. I would like to do something like this:</p>
  
  <pre><code>INSERT INTO Summary (SELECT FROM GetSummary(OtherTable.x, OtherTable.y)
  FROM OtherTable WHERE &lt;some query&gt;);
  </code></pre>
  
  <p>That fails because <code>SELECT FROM GetSummary ..</code> doesn't return Summary table rows. The query <code>SELECT * FROM GetSummary ..</code> would do that but then I don't know how to write the query.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Happened to stumble to solution few minutes after posting. The right syntax is</p>
  
  <pre><code>INSERT INTO Summary (SELECT (GetSummary(OtherTable.x, OtherTable.y)).*
  FROM OtherTable WHERE &lt;some query&gt;);
  </code></pre>
  
  <p>The (X).* notation expands the select to columns.</p>