Обсуждение: plpgsql and triggers

Поиск
Список
Период
Сортировка

plpgsql and triggers

От
"Bart Degryse"
Дата:
I'm looking for a way to use a parameter given to a trigger function as fieldname. It should be something like
create function f_makeupper() returns trigger as '
begin
    NEW.TG_ARGV[0] := upper(NEW.TG_ARGV[0]);
    RETURN NEW;
end;
' language 'plpgsql';
create trigger "TRIG_tbltest" before insert on tbltest for each row execute procedure f_makeupper("fieldname");
 
I can create both the function and the trigger, but on inserting a new record I get an error telling me that "record 'new' has no field 'tg_argv'"
 
What am I doing wrong ?
 

Re: plpgsql and triggers

От
Michael Fuhr
Дата:
On Thu, Jun 02, 2005 at 01:57:26PM +0200, Bart Degryse wrote:
>
> I'm looking for a way to use a parameter given to a trigger function as
> fieldname. It should be something like
> create function f_makeupper() returns trigger as '
> begin
>     NEW.TG_ARGV[0] := upper(NEW.TG_ARGV[0]);
>     RETURN NEW;
> end;
> ' language 'plpgsql';

As you've discovered, this doesn't work in PL/pgSQL: the above code
references the new row's TG_ARGV column, which doesn't exist.  This
comes up frequently; see the list archives for past discussion.  The
usual advice is to use a language like PL/Perl, PL/Tcl, PL/Python, etc.
that provides this capability.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/