Re: SQL error

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: x asasaxax <xanaruto(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL error
Date: 2008-04-19 15:08:06
Message-ID: 480A0AD6.9020405@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

x asasaxax wrote:
> HI everyone,
>
>
> I´m trying to capture all the possible errors that a statement can have.
> And, if there´s any error i will do a rollback; What i´m trying to do its:
> BEGIN
> insert into temp values(1, 2, 3);
> IF ANY_ERROR_OCCURED THEN
> ROLLBACK;
> RETURN FALSE;
> END IF;
> END;
>
> Did anyone knows how can i do that?
>
Use a PL/pgSQL stored procedure. PostgreSQL does not support ad-hoc
blocks or unnamed procedures, but it's OK to create the procedure, use
it, and drop it again.

http://www.postgresql.org/docs/current/static/plpgsql.html

and particularly:

http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

However, the EXCEPTION blocks you use to trap errors aren't free in
performance terms, so you should probably look for other approaches first.

--
Craig Ringer

In response to

  • SQL error at 2008-04-19 14:47:19 from x asasaxax

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-04-19 15:17:05 Re: SQL error
Previous Message Martijn van Oosterhout 2008-04-19 15:07:23 Re: SQL error