I am interested in learning how to use dynamic functions in Postgres. I basically need a dynamic function that will spit out a table or a subtable (a few chosen columns from an existing table).
I've created the following eval() function, but it is not working as I'd like it to. 
I would like my function to return the result of a query that is introduced as a string within the function. The function currently returns only the first value from the first column (enrich_d_dkj_p_k27ac). It seems like I should change my returns from text to something else?
create or replace function eval() returns text
as
$body$
declare
  result text;
begin
  execute 'select enrich_d_dkj_p_k27ac,enrich_lr_dkj_p_k27ac,enrich_r_dkj_p_k27ac
  from dkj_p_k27ac' into result;
  return result;
end;
$body$
language plpgsql;
SELECT eval();
Result is:
eval text
2.4 
But this is basically only the very first value of the first column - I will need the entire table to appear - or in other words - the result of the indicated SELECT.
 
     
    