From: | "Moritz Bayer" <moritz(dot)bayer(at)googlemail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Loop in loop |
Date: | 2007-01-22 14:58:32 |
Message-ID: | c244500b0701220658y56cceffbm63d33791d018e170@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2007-01-22 15:04:37 | Re: triggers and TriggerData |
Previous Message | Ron Peterson | 2007-01-22 14:44:52 | CAST function for user defined type |