Re: for looping - Mailing list pgsql-cygwin

From Michael Adler
Subject Re: for looping
Date
Msg-id Pine.NEB.4.44.0208041335540.9403-100000@reva.sixgirls.org
Whole thread Raw
In response to for looping  ("Michael Labhard" <ince@pacifier.com>)
List pgsql-cygwin
> 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


pgsql-cygwin by date:

Previous
From: "Michael Labhard"
Date:
Subject: for looping
Next
From: "John S. Gage"
Date:
Subject: initdb hangs