title: insert calculated values into two tables with one function
body: <p>I have 2 tables and after insert few columns in first table I need calculate other columns and put aggregated values in second table</p>
  
  <p>for example </p>
  
  <pre><code>a|b|c|       d|e|f|
  1|5| |
  1|5| |
  </code></pre>
  
  <p>I need to insert a and b columns of first table into d and e columns in second table, and c column in first table is value of (b-c).</p>
  
  <p>I have a function like</p>
  
  <pre><code>declare
   cursor1 CURSOR FOR
    SELECT SUM(a) as a, SUM(b) as b
  begin
   FOR cur_rec in cursor 1
    LOOP
     insert into b(d, e)
     values (cur_rec.a, cur_rec.b)
  on conflict etc...
  </code></pre>
  
  <p>how can I insert in first table c column result of (a-b) calculated in this function? all values ~INT</p>
  
  <p>I want result like </p>
  
  <pre><code>a|b|c|       d|e|f|
  1|5|4|       2|10|8
  1|5|4|
  </code></pre>