Re: How do I save data and then raise an exception?

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Rob Richardson <Rob(dot)Richardson(at)rad-con(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How do I save data and then raise an exception?
Date: 2008-10-03 01:44:16
Message-ID: 20081003014416.GM4151@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rob Richardson wrote:

> Here's what I need to do:
>
> IF query_check_fails THEN
> UPDATE some_table SET some_value = 0 WHERE some_condition_is_true;
> RAISE EXCEPTION 'Look, you idiot, do it right next time!';
> END;
>
> I need the update to work, but I need to raise the exception so the C++
> code recognizes the error. How can I do both?

You need an autonomous transaction, which Postgres does not support
directly but you can implement using dblink or a plperl function that
connects back to the database.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jaime Casanova 2008-10-03 02:11:09 Re: How do I save data and then raise an exception?
Previous Message Rob Richardson 2008-10-02 20:25:13 How do I save data and then raise an exception?