X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7FE6430F08B for ; Tue, 17 Jun 2003 09:25:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 89079-03 for ; Tue, 17 Jun 2003 06:25:09 -0300 (ADT) Received: from aldratech.com (unknown [213.154.158.58]) by svr1.postgresql.org (Postfix) with ESMTP id 9386430F0A7 for ; Tue, 17 Jun 2003 06:25:07 -0300 (ADT) Received: from rpopescu.aldratech.com ([192.168.0.6]) by aldratech.com for with eXtremail; Tue, 17 Jun 2003 12:25:06 +3GMT Message-Id: <5.2.1.1.0.20030617121526.02185a50@192.168.0.1> X-Sender: radu.popescu@aldratech.com@192.168.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Tue, 17 Jun 2003 12:25:06 +0300 To: pgsql-sql@postgresql.org From: Radu-Adrian Popescu Subject: Catching DML exceptions in PL/pgSQL Mime-Version: 1.0 Content-Type: text/html; charset="us-ascii" X-Spam-Status: No, hits=1.4 tagged_above=0.0 required=5.0 tests=HTML_30_40, HTML_FONT_FACE_ODD, MIME_HTML_ONLY X-Spam-Level: * X-Archive-Number: 200306/172 X-Sequence-Number: 13930 Hello all,
(and sorry if this has been aswered before)

Take this piece of code for example:
.....................
begin
    _res.code:=1;
    select id into iid from log where id=_id;
    if not found then begin
        _res.msg:=''insert'';
        insert into log (log, data) values (_log, _data);
        if not found
then begin
            _res.msg:=_res.msg || '' error'';
            _res.code:=-1;
        end;
        end if;
    end;
    else begin
.....................
The thing is if _data (parameter) is null and table has a (data <> null) check, the insert would fail and abort the function before my "if not found" test.

I'm porting a java app. from mssql to postgresql, and the java code relies on the stored procedure to always return it's status (in _res.code in this case).

Is there anything I can do to make sure the function always returns _res ?
Something along the lines of Oracle's exception handling, or the @@error trick in mssql ?


Regards,
--
Radu-Adrian Popescu
CSA, DBA, Developer
Aldratech Ltd.