title: PostgreSQL: ERROR: $name$ is not a scalar variable
body: <p>There is a function that returns 3 parameters one of which is a composite type:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION f1(
    p_text text,
    OUT result_status_id smallint,
    OUT result_status_msg text,
    OUT result_my_type my_type
    )
    RETURNS record AS
  $BODY$
  --body here
  $BODY$
  LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER
    COST 100
  </code></pre>
  
  <p>The composite type my_type looks like following:</p>
  
  <pre><code>CREATE TYPE my_type AS
     (d_real real,
      d_int1 integer,
      d_int2 integer,
      d_int3 integer,
      d_int4 integer,
      d_int5 integer,
      d_int6 integer,
      d_int7 integer,
      d_int8 integer,
      d_int9 integer,
      d_int10 integer,
      d_bool boolean,
      d_date date,
      d_text text
  );
  </code></pre>
  
  <p>There is another function f2 that calls function f1 in its body:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION f2(
      p_text text
  )
    RETURNS record AS
  $BODY$
  DECLARE
      l_status_id smallint;
      l_status_msg text;
      l_my_type my_type;
  BEGIN
  --some logic here
  
  --this statement fails
    SELECT * FROM f1(p_text) 'x' 
    INTO l_status_id, l_status_msg, l_my_type;
  
  --logic continues here
  END;
  $BODY$
    LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER
    COST 100;
  </code></pre>
  
  <p>The problem is that when executing sql with the function I receive the following error:</p>
  
  <pre><code>ERROR: "l_my_type" is not a scalar variable
  </code></pre>
  
  <p>How may one get a composite type object from another function?</p>