Thread: Re: Loop in loop

Re: Loop in loop

From
"Moritz Bayer"
Date:
OK, this looks better:


CREATE OR REPLACE FUNCTION getregistrationtagging()
  RETURNS SETOF ty_usertracking AS
$BODY$
DECLARE objReturn ty_usertracking%rowtype;
BEGIN
        for objReturn IN
        SELECT     date_part('day',trackdate) as ty_day,
            date_part('month',trackdate) as ty_month,
            date_part('year',trackdate) as ty_year,
            tag as ty_tag,
            designid as ty_designid
        FROM tbl_usertracking_registration
        GROUP BY     date_part('day',trackdate),
                date_part('month',trackdate),
                date_part('year',trackdate),
                tag,
                designid
           loop
               SELECT INTO objReturn.ty_count count(*) FROM tbl_usertracking_registration
                    WHERE date_part('day',trackdate)=objReturn.ty_day
                    AND date_part('month',trackdate)= objReturn.ty_month
                    AND date_part('year',trackdate)=objReturn.ty_year
                    AND tag=objReturn.ty_tag
                    AND designid=objReturn.ty_designid;
                       SELECT INTO objReturn.ty_date max(trackdate) FROM tbl_usertracking_registration
                    WHERE date_part('day',trackdate)=objReturn.ty_day
                    AND date_part('month',trackdate)=objReturn.ty_month
                    AND date_part('year',trackdate)=objReturn.ty_year
                    AND tag=objReturn.ty_tag
                    AND designid=objReturn.ty_designid;

            return next objReturn;   
     END LOOP;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION getregistrationtagging() OWNER TO postgres;

But still the question:
Is it possible to put a loop into a loop?  Or doesn't it make sense at all?

Kind regards,
Mo

Re: Loop in loop

From
"A. Kretschmer"
Date:
am  Mon, dem 22.01.2007, um 15:58:32 +0100 mailte Moritz Bayer folgendes:
>
> But still the question:
> Is it possible to put a loop into a loop?  Or doesn't it make sense at all?

Yes, is possible, why not? And sometimes it make sense...


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

Re: Loop in loop

From
George Weaver
Date:

----Original Message From: Moritz Bayer

>But still the question:
>Is it possible to put a loop into a loop?  Or doesn't it make sense at all?

I'm not sure what the OP was about, but Yes, it it possible to put a loop into a loop.  See:

http://www.postgresql.org/docs/8.2/static/plpgsql-control-structures.html

particularly the references to [ <<label>> ] and EXIT [ label ]  and CONTINUE [ label ] for nested loops.

Regards,
George

Re: Loop in loop

From
"Moritz Bayer"
Date:
Hi Andreas,
if it is possible, can you tell me what error I 've put in my first function?

Thanks,
Mo