Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id B4AFF47617E for ; Thu, 13 Jun 2002 05:00:19 -0400 (EDT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by postgresql.org (Postfix) with ESMTP id 3CF36475E99 for ; Thu, 13 Jun 2002 05:00:13 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 17IQSe-0005Df-0V for pgsql-sql@postgresql.org; Thu, 13 Jun 2002 10:00:08 +0100 Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id ED47B11ECF for ; Thu, 13 Jun 2002 09:50:47 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: pgsql-sql@postgresql.org Subject: Re: General trigger function Date: Thu, 13 Jun 2002 09:50:45 +0100 User-Agent: KMail/1.4.1 References: <003401c211e5$9a5f1220$3d04a837@PXXXX> <3D07AFC5.8F5413BF@Yahoo.com> In-Reply-To: <3D07AFC5.8F5413BF@Yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200206130950.45528.dev@archonet.com> X-Archive-Number: 200206/165 X-Sequence-Number: 8130 On Wednesday 12 Jun 2002 9:32 pm, Jan Wieck wrote: > GRIMOIS Eric wrote: > > Hi all > > > > I read in the doc than a same function can be used for several triggers. > > I tried to create a function who updates a field with a timestamp and > > another field with the user name. This function is fired by triggers in > > several tables. > > It only works if updated fields have same names in all tables. I failed > > to create a function where fields names are parameters of the function. > > You could do that with the EXECUTE functionality. But that > causes *every* execution of these statemets not beeing > cacheable, so it'll have an impact on performance. Or look in the cookbook linked from techdocs.postgresql.org - there's an=20 example in there of a "trigger maker" which builds last-changed tracking=20 triggers and functions. You do something like: select lastchg_addto('TABLE-NAME','TIMESTAMP-COLUMN-NAME') And it creates the relevant function and trigger code then EXECUTEs it.=20 Shouldn't take much to alter it for your purposes - Richard Huxton=20