From: | "Brendan Jurd" <direvus(at)gmail(dot)com> |
---|---|
To: | "Jeremiasz Miedzinski" <jmiedzinski(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [PL/pgSQL] How should I use FOUND special variable. Documentation is little unclear for me |
Date: | 2006-11-10 16:16:55 |
Message-ID: | 37ed240d0611100816v70deaf5bqc1061bbc7fc3130b@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 11/9/06, Jeremiasz Miedzinski <jmiedzinski(at)gmail(dot)com> wrote:
> Now, I need to do the same action in PL/pgSQL. It's rather simple, but I
> don't know how to use FOUND variable described in documentation:
>
> FETCH retrieves the next row from the cursor into a target, which may be a
> row variable, a record variable, or a comma-separated list of simple
> variables, just like SELECT INTO. As with SELECT INTO, the special variable
> FOUND may be checked to see whether a row was obtained or not.
>
> When I'm trying to use it in Oracle way, my DB reports error. Also I tried
> to use it like that:
>
> IF NOT crs_cnt%FOUND THEN ...
>
In PL/pgsql, FOUND is just a variable which is set to true or false on
the outcome of each SELECT or FETCH.
To use it in your example, you could do:
OPEN crs_cnt(start_millis, end_millis);
LOOP
FETCH crs_cnt into row_cnt;
EXIT WHEN NOT FOUND;
-- do stuff with the row
END LOOP;
CLOSE crs_cnt;
Regards,
BJ
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-11-10 16:23:49 | Re: Problem with pg_dump |
Previous Message | Ben | 2006-11-10 16:05:32 | Re: Database Mirroring Solution |