Re: Referencing any field in a trigger

From: Robert Fitzpatrick <lists(at)webtent(dot)net>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Referencing any field in a trigger
Date: 2007-05-25 20:15:14
Message-ID: 1180124114.15450.67.camel@columbus.webtent.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 2007-05-25 at 13:45 -0400, Alvaro Herrera wrote:
> Robert Fitzpatrick wrote:
>
> > But still, how would I reference all fields using the pl/perl? Can I
> > specify column numbers versus names as in '$_TD->{new}{1}' for the first
> > column and loop or something? For instance, I would like to be able to
> > say if any NEW column has a single asterisk only, set it to '%%%'.
>
> Well, do a foreach ($_TD->{new}) or foreach (keys $_TD->{new}) (not sure
> of the exact syntax but if you're used to Perl you can figure it out).
>

You gotta love pgsql, took a bit, but done...

foreach $i (keys %{$_TD->{new}}) {
if (${$_TD->{new}}{$i} eq '*') {
${$_TD->{new}}{$i} = '%%%';
} else {
${$_TD->{new}}{$i} =~ s/\*/\%/g;
}
}
return "MODIFY";

--
Robert

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2007-05-25 20:42:37 Re: why postgresql over other RDBMS
Previous Message Robert Treat 2007-05-25 20:01:02 Re: Vacuum DB in Postgres Vs similar concept in other RDBMS