title: postgresql functions - execute 'create table...' - unexpected results
body: <p>I'm writing a function which does the following:</p>
  
  <p>Create a temporary table with a single field.
  This field is the result of the sum of up to 5 variables from a specific table.</p>
  
  <p>Let's say I have the following table:</p>
  
  <pre><code>create table src (x1 numeric, x2 numeric);
  insert into src values (2,1),(5,2),(10,4);
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>create or replace function qwert(cod numeric, v1 numeric default 0
      , v2 numeric default 0, v3 numeric default 0, v4 numeric default 0,
      v5 numeric default 0)
  returns numeric as
  $func$
  declare vv numeric;
  begin
  vv = v1+v2+v3+v4+v5;
  execute '
      drop table if exists t' || cod || '; 
      create temporary table t' || cod || ' as 
      select ' || vv || ' ;'
      ;
  return vv;
  end
  $func$ language plpgsql;
  </code></pre>
  
  <p>If I run:
          select qwert(1, x1,x2) from src;</p>
  
  <p>The expected result is a table t1:</p>
  
  <pre><code> column1 
  ---------
         3
         7
         14
  (3 rows)
  </code></pre>
  
  <p>Instead the result is:</p>
  
  <pre><code>db1=# select * from t1;
   ?column? 
  ----------
         14
  (1 row)
  </code></pre>
  
  <p>In my code, line:
      return vv;
  is only there to check whether vv was being created correctly.</p>
  
  <p>Could someone help you this?</p>