Thread: can you do a for loop on a function call in PL/PGSQL?

can you do a for loop on a function call in PL/PGSQL?

From
"Eric Peters"
Date:
Basically what I'm trying to do is:

   FOR zone_dns_r3 IN zone_dns_from_zone_dns_id(zone_dns_r.zone_dns_id,
zone_dns_r2.zone_dns_id)
   LOOP
    RETURN (zone_dns_r3) AND RESUME;
   END LOOP;

Where I want to loop the results from a stored procedure (I happen to be
calling it recusively)
NOTICE:  plpgsql: ERROR during compile of get_zone_dns_from_zone_dns_id near
line 29
ERROR:  parse error at or near "get_zone_dns_from_zone_dns_id"

Is basically what its having problems with "the zone_dns_from_zone_dns_id("
call

Any ideas?


My full stored procedure:

CREATE FUNCTION get_zone_dns_from_zone_dns_id(INTEGER, INTEGER) RETURNS
setof zone_dns AS '
DECLARE
 zone_dns_parent_id_param ALIAS FOR $1;
 zone_dns_id_param ALIAS FOR $2;

 zone_dns_r zone_dns%ROWTYPE;
 zone_dns_r2 zone_dns%ROWTYPE;
 zone_dns_r3 zone_dns%ROWTYPE;

BEGIN

 FOR zone_dns_r IN
  select
   zone_dns.*
  from
   zone_dns
  where
   zone.zone_dns_id = zone_dns_id_param AND
   zone_dns.zone_dns_parent_id = zone_dns_parent_id_param
 LOOP
  FOR zone_dns_r2 IN
   select
    zone_dns.*
   from
    zone_dns
   where
    zone_dns.zone_dns_parent_id = zone_dns_r.zone_dns_id
  LOOP

   FOR zone_dns_r3 IN zone_dns_from_zone_dns_id(zone_dns_r.zone_dns_id,
zone_dns_r2.zone_dns_id)
   LOOP
    RETURN (zone_dns_r3) AND RESUME;
   END LOOP;
  END LOOP;

  RETURN (zone_dns_r) AND RESUME;
 END LOOP;

 RETURN;

END;
' LANGUAGE 'plpgsql';