Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8540F475E77 for ; Tue, 15 Oct 2002 21:28:52 -0400 (EDT) Received: from smtp014.mail.yahoo.com (smtp014.mail.yahoo.com [216.136.173.58]) by postgresql.org (Postfix) with SMTP id B4A67474E42 for ; Tue, 15 Oct 2002 21:28:51 -0400 (EDT) Received: from psc.progress.com (HELO Yahoo.com) (janwieck@192.233.92.200 with plain) by smtp.mail.vip.sc5.yahoo.com with SMTP; 15 Oct 2002 18:46:09 -0000 Message-ID: <3DAC626B.4DEB45E8@Yahoo.com> Date: Tue, 15 Oct 2002 14:46:03 -0400 From: Jan Wieck Organization: Home X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) X-Accept-Language: en,ru MIME-Version: 1.0 To: Brian Blaha Cc: pgsql-sql@postgresql.org Subject: Re: SQL function triggers References: <3DABB04B.8000104@umr.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/170 X-Sequence-Number: 9887 Brian Blaha wrote: > > I would like to write a function as a set of SQL statements, and then > use that function > in a trigger. However, since triggers require a return type of opaque, > and SQL functions > cannot return type opaque, this doesn't look possible. Am I missing > something? The SQL > that I would expect to do this is below. Incidentally, on an insert, > would the trigger fire > once, twice, or infinitely? > > create table test( > a integer, > b integer > ) without oids; > > create function test_func( test.a%TYPE ) > RETURNS ????? > AS > 'update test set b = a where a = $1;' > language SQL > with (isstrict); > > create trigger test_trig after update > on test for each row > execute procedure test_func( a ); If you intend to modify the updated row only with information available in the row itself (as in your example), a BEFORE trigger in PL/pgSQL modifying and returning NEW should get the job done. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #