pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Radu-Adrian Popescu <radu.popescu@aldratech.com>
To: pgsql-sql@postgresql.org
Subject: Catching DML exceptions in PL/pgSQL
Date: Tue, 17 Jun 2003 12:25:06 +0300
Message-ID: <5.2.1.1.0.20030617121526.02185a50@192.168.0.1> (raw)

<html>
<body>
Hello all,<br>
(and sorry if this has been aswered before)<br><br>
Take this piece of code for example:<br>
.....................<br>
<font face="Courier, Courier">begin<br>
&nbsp;&nbsp;&nbsp; _res.code:=1;<br>
&nbsp;&nbsp;&nbsp; select id into iid from log where id=_id;<br>
&nbsp;&nbsp;&nbsp; if not found then begin<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _res.msg:=''insert'';<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>insert into log (log, data)
values (_log, _data);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not found</b> then
begin<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_res.msg:=_res.msg || '' error'';<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_res.code:=-1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if;<br>
&nbsp;&nbsp;&nbsp; end;<br>
&nbsp;&nbsp;&nbsp; else begin<br>
</font>.....................<br>
The thing is if _data (parameter) is null and table has a (data &lt;&gt;
null) check, the insert would fail and abort the function before my
&quot;if not found&quot; test.<br><br>
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).<br><br>
Is there anything I can do to make sure the function always returns _res
?<br>
Something along the lines of Oracle's exception handling, or the @@error
trick in mssql ?<br><br>
<br>
<x-sigsep><p></x-sigsep>
Regards,<br>
--<br>
Radu-Adrian Popescu<br>
CSA, DBA, Developer<br>
Aldratech Ltd.</body>
</html>





view thread (7+ messages)  latest in thread

Message-ID: <5.2.1.1.0.20030617121526.02185a50@192.168.0.1>
Permalink:  ../5.2.1.1.0.20030617121526.02185a50@192.168.0.1/
Also on:    postgresql.org/message-id/5.2.1.1.0.20030617121526.02185a50@192.168.0.1

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: radu.popescu@aldratech.com
  Subject: Re: Catching DML exceptions in PL/pgSQL
  In-Reply-To: <5.2.1.1.0.20030617121526.02185a50@192.168.0.1>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox