title: PL/pgSQL Return SETOF Records Error
body: <p>I am relatively new to postgresql and battling my way to get familiarized with it. I had run in to an error while writing a new pl/sql function. <strong>ERROR:  type "ordered_parts" does not exist</strong></p>
  
  <pre><code>CREATE OR REPLACE FUNCTION get_ordered_parts(var_bill_to integer)
    RETURNS SETOF ordered_parts AS
  $BODY$
  declare
  
      var_ordered_id record;
      var_part ordered_parts;
  
  begin
  
      for var_ordered in select order_id from view_orders where bill_to = var_bill_to
      loop
  
          for var_part select os.po_num,os.received,os.customer_note,orders.part_num,orders.description,orders.order_id,orders.remaining_quantity from (select vli.part_num,vli.description,vli.order_id,vli.quantity - vli.quantity_shipped as remaining_quantity from view_line_items as vli where vli.order_id in (select order_id from view_orders where bill_to = var_bill_to and order_id = var_ordered.order_id) and vli.quantity - vli.quantity_shipped &gt; 0)as orders left join order_sales as os on orders.order_id = os.order_id
          then
  
              -- Then we've found a leaf part
              return next var_part;
  
          end if;
  
      end loop;
  
  end;
  $BODY$
    LANGUAGE 'plpgsql' VOLATILE
    COST 100
    ROWS 1000;
  ALTER FUNCTION get_ordered_parts(integer) OWNER TO postgres;
  </code></pre>