for looping
for looping
От:
"Michael Labhard" <ince@pacifier.com>
Дата:
Does FOR LOOP work on SELECT? The following simple function looks good to me but does not compile because of "missing .. at end of SQL expression". CREATE FUNCTION get_all_diffs() RETURNS FLOAT AS ' DECLARE i INTEGER := 0; sym_diff FLOAT := 0.0; BEGIN FOR row IN SELECT * FROM "tblTrades" LOOP i := i+1; END LOOP; RETURN sym_diff; END;' LANGUAGE 'plpgsql' ; SELECT get_all_diffs();
Re: for looping
От:
Michael Adler <adler@glimpser.org>
Дата:
> Does FOR LOOP work on SELECT? The following simple function looks good to > me but does not compile because of "missing .. at end of SQL expression". you need to the declare the row record DECLARE row RECORD; BEGIN > > CREATE FUNCTION get_all_diffs() > RETURNS FLOAT AS ' > DECLARE > i INTEGER := 0; > sym_diff FLOAT := 0.0; > > BEGIN > FOR row IN SELECT * FROM "tblTrades" LOOP > i := i+1; > END LOOP; > > RETURN sym_diff; > END;' > > LANGUAGE 'plpgsql' > ; > > SELECT get_all_diffs(); > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > Mike