View Single Post

   
  #2 (permalink)  
Old 04-09-2008, 03:12 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: Generic triggers ?

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.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFGLiVUIB7bNG8LQkwRAgxpAJwJDamHyvdPt4a/vKQ7Xl1GK+AjFQCeNJIx
0gUkiVGcHGh6dxdHy/YeM+Y=
=vw4h
-----END PGP SIGNATURE-----

Reply With Quote