Re: Question about catching exception

From: tv(at)fuzzy(dot)cz
To: "A B" <gentosaker(at)gmail(dot)com>
Cc: "postgresql Forums" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Question about catching exception
Date: 2010-11-26 10:04:03
Message-ID: decfe71cc7af426aa9d0a4e80559a354.squirrel@sq.gransy.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hello
>
> you have to parse a sqlerrm variable

That's one way to do that. Another - more complex but more correct in many
cases is using two separate blocks.

BEGIN
... do stuff involving constraint A
EXCEPTION
WHEN unique_violation THEN ...
END;

BEGIN
... do stuff involving constraint B
EXCEPTION
WHEN unique_violation THEN ...
END;

But that's not possible if there are two unique constraints involved in a
single SQL statement (e.g. inserting into a table with two unique
constraints).

regards
Tomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message c k 2010-11-26 11:58:52 Re: [GENERAL] plpyhton
Previous Message Pavel Stehule 2010-11-26 09:52:48 Re: Question about catching exception