The following stored procedure for a postgresql database attempts to insert into a temporary table 'result' of type result_load_status ,which is a table in database, and return this temporary table. When function is executed, the output window shows a message 'result does not exist'. How to fix it or any other way it should be done?
Following is the definition of stored procedure:
create or replace function trial5(table_name text) returns table(up_link double precision,time_stamp timestamp without time zone) as $$ declare b integer default 1; declare c integer default 2; declare result result_load_status; begin execute 'select ' || table_name ||'.up_link,' || table_name || '.time_stamp from' || table_name || ' where bar2= ' || b into result; execute 'select ' || table_name ||'.up_link,' || table_name || '.time_stamp from' || table_name || ' where bar2= ' || c into result; return query select * from result; end $$ language plpgsql;
ERROR: relation "result" does not exist
LINE 1: select * from result