X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9303C9FC34C for ; Mon, 28 Aug 2006 11:58:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 63190-04 for ; Mon, 28 Aug 2006 11:57:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id A9F3F9FCF5C for ; Mon, 28 Aug 2006 11:57:50 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id k7SEvcRx041058 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Aug 2006 08:57:41 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id k7SEvc9A005118; Mon, 28 Aug 2006 08:57:38 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id k7SEvcY7005117; Mon, 28 Aug 2006 08:57:38 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 28 Aug 2006 08:57:38 -0600 From: Michael Fuhr To: Henry Ortega Cc: pgsql-sql@postgresql.org Subject: Re: Trigger on Insert to Update only newly inserted fields? Message-ID: <20060828145737.GA5004@winnie.fuhr.org> References: <2bffcc330608280702y16c25090i816589e20163e7e8@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2bffcc330608280702y16c25090i816589e20163e7e8@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.184 tagged_above=0 required=5 tests=AWL, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/222 X-Sequence-Number: 26180 On Mon, Aug 28, 2006 at 10:02:32AM -0400, Henry Ortega wrote: > I have a On Insert Trigger that updates one of the columns in that same > table. > > Is there a way for the trigger to run only for the newly inserted records? > Instead of all records in the database? Row-level INSERT and UPDATE triggers run only for the rows being inserted or updated. What are you doing that suggests otherwise? > E.g.: > ID Start_Date End_Date > 001 08-01-2006 > 002 08-02-2006 > > On Insert/Update, Update End_Date=now(). > I want that to run only on new records.or the updated > record. How can I do this? Row-level BEFORE triggers can modify the row they're processing -- is that what you're looking for? Something like this? CREATE FUNCTION trigfunc() RETURNS trigger AS $$ BEGIN NEW.end_date := current_date; RETURN NEW; END; $$ LANGUAGE plpgsql; If that's not what you mean then please elaborate. -- Michael Fuhr