Re: Generic triggers ? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Generic triggers ?
Date
Msg-id 20070424154212.GF2579@svana.org
Whole thread Raw
In response to Generic triggers ?  ("Andy Dale" <andy.dale@gmail.com>)
List pgsql-general
On Tue, Apr 24, 2007 at 05:35:09PM +0200, Andy Dale wrote:
> Hi,
>
> I wanted to setup a simple "generic" type trigger.  What a mean by generic
> is that i don't want to hardcode the
> NEW.<column> or OLD.<column> calls, i searched for a way to loop over
> the NEW/OLD rowtypes but could not figure out how it should be done.

You're trying to do something that pl/pgsql it notoriously bad at. I
suggest you use some more dynamic language like perl/python/etc.

> The above code does nothing useful and is only to test out the concept.  The
> problem comes from NEW.colnames[i] because the NEW rowtype does not have a
> column called colnames.  Can anyone tell me how to append the value of
> colnames[i] to NEW so it would work, or is it even possible to iterate of
> the NEW/OLD rowtype without having to know the column names ?

Not in pl/pgsql (being statically typed). In some other languages you can.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: How does server handle clients that disconnect ungracefully?
Next
From: Richard Huxton
Date:
Subject: Re: Generic triggers ?