Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 522A7475E91 for ; Fri, 17 Jan 2003 10:42:27 -0500 (EST) Received: from ece.rice.edu (ece.rice.edu [128.42.4.34]) by postgresql.org (Postfix) with ESMTP id CFA88475E1E for ; Fri, 17 Jan 2003 10:42:26 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by ece.rice.edu (Postfix) with SMTP id 6C3AC68AAC; Fri, 17 Jan 2003 09:42:31 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by ece.rice.edu (Postfix) with ESMTP id 1EB5A68A6F; Fri, 17 Jan 2003 09:42:31 -0600 (CST) Received: from wallace.ece.rice.edu (wallace.ece.rice.edu [128.42.12.154]) by ece.rice.edu (Postfix) with ESMTP id 54BEF68A5B; Fri, 17 Jan 2003 09:42:30 -0600 (CST) Received: from reedstrm by wallace.ece.rice.edu with local (Exim 3.36 #1 (Debian)) id 18ZYdZ-0004CJ-00; Fri, 17 Jan 2003 09:42:29 -0600 Date: Fri, 17 Jan 2003 09:42:29 -0600 From: "Ross J. Reedstrom" To: Yudha Setiawan Cc: pgsql-admin@postgresql.org Subject: Re: Do Something before Abort on Trigger ??? Message-ID: <20030117154229.GA15778@wallace.ece.rice.edu> Mail-Followup-To: "Ross J. Reedstrom" , Yudha Setiawan , pgsql-admin@postgresql.org References: <023f01c2bc75$bdce13b0$ea00a8c0@yudha> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <023f01c2bc75$bdce13b0$ea00a8c0@yudha> User-Agent: Mutt/1.4i X-Virus-Scanned: by AMaViS snapshot-20020300 X-DCC--Metrics: ece.rice.edu 1066; Body=1 Fuz1=1 Fuz2=1 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/192 X-Sequence-Number: 7034 On Wed, Jan 15, 2003 at 04:08:40PM +0700, Yudha Setiawan wrote: > Somebody gimme your hand plz. > > Using my previous Database I used to be like that; > " ALTER TRIGGER tr_T_DtlPO ON dbo.T_DtlPO FOR UPDATE AS > bla..bla..bla... > IF @OldQty <> @NewQty BEGIN > ROLLBACK > INSERT INTO T_My_ListError(fc_code,fv_descript) > VALUES('12345','No Authority to Change Qty') > END" > So I'v already write the error code to table T_My_ListError before aborting this session > ----------------------------------------------------------------------------------------- > And I Tried on Postgre like that; > " create or replace function fn_tr_t_dtlpo returns trigger as' > begin > bla..bla...; > if new.fn_qty != old.fn_qty then > raise exception ''Error 12345''; > insert into t_my_listerror(fc_code,fv_descript) > values(''12345'',''No Authority to Change Qty''); > end if; > end;' language 'plpgsql'; > " > But I Couldn't get any records at all on t_my_listerror. Even when put the insert statement > (insert into t_my_listerror...bla..bla) before raise exception. Hmm, I think you may be out of luck, if you really _have_ to abort the transaction, since PostgreSQL has no way to violate the transactional integrity: anything you do inside a function that's in a transaction that fails will rollback. Alternatively, you can supress the UPDATE by setting new.fn_qty = old.fn_qty, INSERTing a line in your errors table, and even firing off a NOTICE so an LISTENing frontend can tell the user about the problem. This will let the rest of the transaction commit, however. Sorry, Ross -- Ross Reedstrom, Ph.D. reedstrm@rice.edu Research Scientist phone: 713-348-6166 The Connexions Project http://cnx./rice.edu fax: 713-348-6182 Rice University MS-39 Houston, TX 77005