title: Pass table to postgreSQL function, execute select statement, return table
body: <p>I'm transitioning to postgreSQL from MSSQL and still working out the syntax for procedural programming. The idea is to create a function that will take a table as an input/parameter, execute a series of <code>SELECT</code> statements against this input table (no temp tables; the <code>SELECT</code> statements will be executed with CTEs), and <code>RETURN</code> a final table. </p>
  
  <p>The input table would be very straightforward:</p>
  
  <pre><code>Col_1      Col_2       Col_3
  ----------------------------
  2           5           12  
  </code></pre>
  
  <p>I want to use each of the fields in the input table to calculate a number (in this example, summing <code>Col_1</code>, <code>Col_2</code>, and <code>Col_3</code>), append it to the input table, and create an output table that appears as such:</p>
  
  <pre><code>Col 1      Col_2       Col_3      Col_4
  ---------------------------------------
  2           5           12        19   
  </code></pre>
  
  <p>My attempt at the code:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION summing_function(input_table)
  RETURNS output_table(Col_1 INT, Col_2 INT, Col_3 INT, Col_4 INT) AS
  $$
  SELECT 
      i.*
      , i."Col_1" + i."Col_2" + i."Col_3" as sum
  INTO output_table
  FROM input_table i
  $$
  LANGUAGE SQL;
  </code></pre>
  
  <p>Obviously everything between the dollar quotes is incomplete/wrong. What's the correct postgreSQL syntax for piece between the dollar quotes?</p>