Thread: exception handling and CONTINUE

exception handling and CONTINUE

From
"Marcin Krawczyk"
Date:
Hi all. Can anyone tell me if there's a way to use CONTINUE clause outside the loop ?
An example :
 
FOR a IN SELECT * FROM xxx
LOOP
 
INSERT INTO yyy VALUES (a.***, ..)
 
END LOOP;
 
EXCEPTION WHEN unique_violation THEN CONTINUE;
 
I get an error saying I can't use CONTINUE outside of a loop. Is there a way around this ?
 
regards
mk

Re: exception handling and CONTINUE

From
Alvaro Herrera
Date:
Marcin Krawczyk escribió:
> Hi all. Can anyone tell me if there's a way to use CONTINUE clause outside
> the loop ?
> An example :
> 
> FOR a IN SELECT * FROM xxx
> LOOP
> 
> INSERT INTO yyy VALUES (a.***, ..)
> 
> END LOOP;
> 
> EXCEPTION WHEN unique_violation THEN CONTINUE;

Try something like this:

for a in select * from xxx
loop begin   insert into yyy values (...) exception when unique_violation then   null;    -- noop, just for clarity
end;
end loop;

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: exception handling and CONTINUE

From
"Pavel Stehule"
Date:
no, you can use CONTINUE only in loop. When you wont ignore exception,
just do nothing
For example, the following two fragments of code are equivalent:
   BEGIN       y := x / 0;   EXCEPTION       WHEN division_by_zero THEN           NULL;  -- ignore the error   END;
   BEGIN       y := x / 0;   EXCEPTION       WHEN division_by_zero THEN  -- ignore the error   END;

http://www.postgresql.org/docs/8.3/static/plpgsql-statements.html

Regards
Pavel Stehule

2008/7/8 Marcin Krawczyk <jankes.mk@gmail.com>:
> Hi all. Can anyone tell me if there's a way to use CONTINUE clause outside
> the loop ?
> An example :
>
> FOR a IN SELECT * FROM xxx
> LOOP
>
> INSERT INTO yyy VALUES (a.***, ..)
>
> END LOOP;
>
> EXCEPTION WHEN unique_violation THEN CONTINUE;
>
> I get an error saying I can't use CONTINUE outside of a loop. Is there a way
> around this ?
>
> regards
> mk


Re: exception handling and CONTINUE

From
"Marcin Krawczyk"
Date:
<p>Thank you guys. <p>Alvaro your idea works tha way I wanted. Why didn't I think about it ? :)<p>regards<p>mk