Re: [Fwd: Re: Trigger Procedures]

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Steve Tucknott <steve(at)retsol(dot)co(dot)uk>
Cc: PostGreSQL <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [Fwd: Re: Trigger Procedures]
Date: 2005-05-13 14:20:45
Message-ID: 20050513071811.T97417@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Thu, 13 May 2005, Steve Tucknott wrote:

> Maybe I can explain a bit better.
> We have a generic procedure that takes table names, record numbers and
> text and then creates an audit. There is a trigger automatically created
> for each table that needs to be audited. Under Informix (this is a
> legacy procedure that is being converted), I can pass NEW into the
> generic function - so I can have different 'named' fields being passed.
> In the generic function the names of the passed fields (ie the variable
> names) becomes static. IE if the trigger is on table A I pass field A,
> if on table B I pass field B (both being same data type). In the generic
> procedure this passed parameter is mapped to a variable called
> 'inputField'. So my procedure doesn't have to worry that in reality
> inputField is field A or field B and I can use simple statements like
> INSERT INTO auditTable VALUES(inputField.......
> Using PostGreSQL (7.4.5) it appear that I cannot pass NEW fields into
> the generic function - so it means that the function has to become
> 'aware' of the source. IE the procedure now has to do 'if the trigger
> source table is table A then use NEW.fieldA ...... if the trigger source
> table is table B then use NEW.fieldB ...... etc'.

Some of the PLs (not plpgsql) allow indirect references via field name
which might allow you to pass the name of field as the trigger argument.
That might be a good fit for what you are doing at the cost of having to
use one of the other languages.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message McCormick, Bill 2005-05-13 17:39:21 Help: Input Error Notice
Previous Message John DeSoi 2005-05-13 12:53:51 Re: Starting the Database