title: Select integer returning function result into variable postgres
body: <p>In Postgres, I'm writing a test script for a function (stored procedure) I wrote. The function returns and integer, the id of the row inserted. In the test script I want to select that id into a variable and show everything has been inserted correctly.</p>
  
  <p>The function looks like this:</p>
  
  <pre><code>CREATE FUNCTION create_factor(p_name VARCHAR(255))
    RETURNS integer AS
  $$
  DECLARE v_insert_id INTEGER;
  BEGIN
      ....
      RETURN v_insert_id AS id;
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>The psql script looks like this:</p>
  
  <pre><code>BEGIN;
  
  \i create_factor.sql
  
  DO $$
  declare factorId integer;
  
  select create_factor into factorId from    /* have tried selecting * as well */
  create_factor(
      'my factor'::VARCHAR(255)
  );
  
  \x
  
  select * from factors where name='my factor' and id=factorId;
  
  \x
  
  select k.key_name, v.value
  from factors f
  join factor_type_key_store k on k.factor_type_id = f.factor_type_id
  join factor_key_value_store v on v.factor_type_key_store_id=k.id ;
  
  END$$;
  
  ROLLBACK;
  </code></pre>
  
  <p>The error I get is as follows:</p>
  
  <blockquote>
    <p>psql:create_factor_test.sql:31: ERROR:  invalid type name
    "create_factor.id into factorId from</p>
  </blockquote>
  
  <p>clearly referring to the <code>select into</code> statement. I've switched up both the function definition and the script quite a bit. Not sure what I'm missing.</p>