Forum OpenACS Development: Response to SQL functions returning rowsets (of one type)

You can also pass in table names to PL/pgSQL but I've not succeeded in figuring out exactly how to do anything useful afterwards

Hi!

I've trying to create a function with a table name as an argument, but i cannot use the "SELECT INTO..." statement, it raises an error.

Could someone figure out why this error appears? Could anybody post an example of a function receiving table names as arguments?

create table zz1 (col1 integer);
 
insert into zz1 values(1);
insert into zz1 values(2);
 
create function zztest(text, text) returns integer
as '
declare
    table_name alias for $1;
    column_name alias for $2;
    dyn_query varchar(4000);
    return_value integer;
begin
    dyn_query := ''select into return_value
        sum(''|| quote_ident(column_name) ||'') from ''|| quote_ident(table_name);
    execute dyn_query;
    return return_value;
end;
' language 'plpgsql';
 
--------
test71=# select zztest('zz2', 'col1');
ERROR:  parser: parse error at or near "into"

Thanks in advance