Re: how to force an insert before Raise Exception?

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: giova <giovainstall2(at)yahoo(dot)fr>
Subject: Re: how to force an insert before Raise Exception?
Date: 2011-04-19 14:47:22
Message-ID: 201104190747.22780.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday, April 19, 2011 6:39:23 am giova wrote:
> Hi.
>
> I made a function that Raise exception with some conditions.
> No problem with that, it is the goal.
>
> My problem is that i want to do an INSERT into a log table before to raise
> the exception. But RAISE EXCEPTION cancels my Insert.
>
> How to force the insert to not being cancelled please?
> Note that i want my exception to be raised , so i can't use:
> EXCEPTION WHEN THEN

Why not? From the docs:
"When an error is caught by an EXCEPTION clause, the local variables of the
PL/pgSQL function remain as they were when the error occurred, but all changes
to persistent database state within the block are rolled back. As an example,
consider this fragment: "

And instead of RAISE EXCEPTION use RAISE NOTICE in the exception clause.

>
> Thanks for your help.
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Taras Kopets 2011-04-19 15:26:30 Re: how to force an insert before Raise Exception?
Previous Message Merlin Moncure 2011-04-19 14:02:02 Re: pg_reorg