Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 482F447649C for ; Mon, 9 Dec 2002 11:16:56 -0500 (EST) Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id 2C3204761C0 for ; Mon, 9 Dec 2002 11:12:05 -0500 (EST) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id LAA13765; Mon, 9 Dec 2002 11:11:50 -0500 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma013763; Mon, 9 Dec 02 11:11:28 -0500 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id LAA15787; Mon, 9 Dec 2002 11:10:02 -0500 Message-ID: <3DF4C0B4.68BA54B9@nsd.ca> Date: Mon, 09 Dec 2002 11:11:32 -0500 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-31 i686) X-Accept-Language: en MIME-Version: 1.0 To: josh@agliodbs.com Cc: Bruce Momjian , pgsql-sql Subject: Re: Rules/Trigges Trade-offs References: <200212061634.gB6GYbt02565@candle.pha.pa.us> <200212061525.49284.josh@agliodbs.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/99 X-Sequence-Number: 10687 Josh, Thanks for the info. I need to change an insert into an update when the key already exists. I have been using a rules to test it on a small set (table) and it works. "Rules can't use indexes" just scared me. I will have to test on a larger set. Also, I had the impression that if a trigger returned NULL, one would get the equivalent of "DO NOTHING". Am I wrong with that assumption? JLL Josh Berkus wrote: > > Bruce, Richard, > > > Triggers are mostly for testing/modifying the row being > > inserted/updated, while rules are better for affecting other rows or > > other tables. > > Hmmm. Thought that there were also some other criteria: > > 1) Rules can't use indexes to do their processing, so Rules which query large > secondary tables can be a bad idea (maybe this has changed?) > > 2) Only Rules can "DO INSTEAD"; thus, only Rules are good for defining > Read/Write views. > > 3) There are no AFTER Rules, making, for example, a rule with a table check on > the new data impractical, so you'd want to use Triggers or Constraints > > etc. > > There are, IMHO, some things Rules are better for, and some things Triggers > are better for. I tend to use all Triggers except for updatable views, > simply because using a mix of Rules and Triggers can be very hard to keep > track of, but YMMV. > > -- > -Josh Berkus > Aglio Database Solutions > San Francisco