Re: RETURNING MORE THAN ONE CUSTOM TYPE FROM FUNCTION - Mailing list pgsql-general

From utsav
Subject Re: RETURNING MORE THAN ONE CUSTOM TYPE FROM FUNCTION
Date
Msg-id 1340039090622-5713131.post@n5.nabble.com
Whole thread Raw
In response to Re: RETURNING MORE THAN ONE CUSTOM TYPE FROM FUNCTION  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: RETURNING MORE THAN ONE CUSTOM TYPE FROM FUNCTION
List pgsql-general
-- Table: bar

-- DROP TABLE bar;

CREATE TABLE bar
(
  barid integer,
  barsubid integer,
  barname text
)
WITH (
  OIDS=FALSE
);
ALTER TABLE bar
  OWNER TO postgres;
--------------------------------------------------------------------------------------------
-- Table: foo

-- DROP TABLE foo;

CREATE TABLE foo
(
  fooid integer,
  foosubid integer,
  fooname text
)
WITH (
  OIDS=FALSE
);
ALTER TABLE foo
  OWNER TO postgres;

--------------------------------------------------------------------------------------------


-- Function: getallfoobar()

-- DROP FUNCTION getallfoobar();

CREATE OR REPLACE FUNCTION getallfoobar3(foo OUT foo,bar OUT bar)
  RETURNS SETOF record AS
$BODY$
 DECLARE
     r foo%rowtype;
     r1 bar%rowtype;
 BEGIN
     FOR r IN SELECT * FROM foo
     WHERE fooid > 3
     LOOP
         -- can do some processing here
              RAISE NOTICE 'r == %',r;
         -- return next row of SELECT
     END LOOP;

     FOR r1 IN SELECT * FROM bar
     WHERE barid > 0
     LOOP
         -- can do some processing here
          -- return next row of SELECT
         RAISE NOTICE 'r1 == %',r1;
     END LOOP;
     RETURN NEXT;
 END
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
-----------------------------------------------------------------------------------

select * from getallfoobar3();


--
View this message in context:
http://postgresql.1045698.n5.nabble.com/RETURNING-MORE-THAN-ONE-CUSTOM-TYPE-FROM-FUNCTION-tp5712546p5713131.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

pgsql-general by date:

Previous
From: Chris Travers
Date:
Subject: Re: How to include Tablefunc as an extension
Next
From: utsav
Date:
Subject: Re: RETURNING MORE THAN ONE CUSTOM TYPE FROM FUNCTION