views:

55

answers:

2

Everything's in the title.

I am Looping on a cursor and would like to have the

EXIT WHEN curs%NOTFOUND

when there is no more row, what is the equivalent of %NOTFOUND under PostgreSQL ?

Edit

Or the other cursors attributes %ISOPEN, %EMPTY, etc...

A: 

The FOUND variable

Implicit cursor

SELECT * INTO myrec FROM emp WHERE empname = myname;
IF NOT FOUND THEN
    RAISE EXCEPTION 'employee % not found', myname;
END IF;

With an explicit cursor

...   
    LOOP
        FETCH cursor INTO whatever;
        EXIT IF NOT FOUND;
           do something with whatever
    end LOOP;
TTMAN
That is not exactly what I am looking for. I am aware of this function, but here you are not using any cursor but a SELECT query. Did you get my point ?
Spredzy
Did you try this ? I had try and got an error because of the IF NOT FOUND.
Spredzy
What version of the database are you on and what was the error you get? Can you post your code?
StarShip3000
A: 

Can't test this right now but what if you try this? Check out section title 37.7.3.2. EXIT at this link http://www.postgresql.org/docs/8.2/static/plpgsql-control-structures.html

IF NOT FOUND THEN
    EXIT;
END IF;

OR

EXIT WHEN NOT FOUND;
StarShip3000