plpgsql loop question - Mailing list pgsql-sql

From Andrea Visinoni
Subject plpgsql loop question
Date
Msg-id 4B72DEDE.3070507@autron.it
Whole thread Raw
Responses Re: plpgsql loop question  (Justin Graf <justin@magwerks.com>)
Re: plpgsql loop question  (Adrian Klaver <adrian.klaver@gmail.com>)
List pgsql-sql
hi,
i have a table called "zones": idzone, zone_name
and several tables called zonename_records (same structure), where 
zonename is one of the zone_name in the "zones" table.
What i want to do is a function that union all of this tables 
dinamically based on "zones" table, this is what i've done so far:

CREATE OR REPLACE FUNCTION get_all_records()  RETURNS SETOF record AS
$BODY$DECLARE
zones record;
recs record;
BEGIN
for zones in select lower(zone_name) as n from zones loopfor recs in select * from quote_ident(zones.n || '_records')
loop   return next recs;end loop;
 
end loop;
RETURN;
END;
$BODY$  LANGUAGE 'plpgsql' VOLATILE  COST 100;

but i get this error!

ERROR:  wrong record type supplied in RETURN NEXT
CONTEXT:  PL/pgSQL function "get_all_records" line 9 at RETURN NEXT

Andrea


pgsql-sql by date:

Previous
From: Rob Sargent
Date:
Subject: Re: 'image' table with relationships to different objects
Next
From: Justin Graf
Date:
Subject: Re: plpgsql loop question