Returning Rows in Procedure - Mailing list pgsql-general

From Adarsh Sharma
Subject Returning Rows in Procedure
Date
Msg-id 4DDB6787.3060807@orkash.com
Whole thread Raw
Responses Re: Returning Rows in Procedure  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Returning Rows in Procedure  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: Returning Rows in Procedure  (David Johnston <polobo@yahoo.com>)
List pgsql-general
Dear all,

I need to return the rows of a table which was also created in that
procedure.

I know it is very easy when the table is existed before and we can
specify like this to return

create function a(integer) returns setof exist_table as $$

But it gives error when the table is also created in the procedure like
below :

create function a(integer) returns setof record as $$
declare
a text;
begin
execute 'insert into a values('asdd');
execute 'insert into a values('affffsdd');
execute 'insert into a values('affsdd');
execute 'insert into a values('ashjgdd');
execute 'insert into a values('asfjfgddd');

---Now i want to return the rows of a
 DECLARE
   r a%ROWTYPE;
 BEGIN
   FOR r in SELECT * FROM a
   LOOP
      RETURN NEXT r;
   END LOOP;
  RETURN;
  END;
 END;
$$ LANGUAGE 'plpgsql' ;

ERROR:  relation "user_news_tmp2" does not exist
CONTEXT:  compilation of PL/pgSQL function "create_user_report2" near
line 22

How to achieve this ?

Thanks & best Regards,
Adarsh

pgsql-general by date:

Previous
From: jun yang
Date:
Subject: Re: how to start a procedure after postgresql started.
Next
From: Pavel Stehule
Date:
Subject: Re: Returning Rows in Procedure