Re: trouble with triggers - Mailing list pgsql-general

From Richard Huxton
Subject Re: trouble with triggers
Date
Msg-id 001901c10ed5$a53c4d20$1001a8c0@archonet.com
Whole thread Raw
In response to trouble with triggers  ("Robert Treat" <robertt@auctionsolutions.com>)
List pgsql-general
From: "Robert Treat" <robertt@auctionsolutions.com>

> CREATE TRIGGER formatname BEFORE update OR insert ON mytable FOR EACH row
> EXECUTE PROCEDURE lower(name);

> ERROR:  CreateTrigger: function lower() does not exist
>
> obviously this does exist, since I can do inserts/updates/selects using
> lower(). I have also tried creating my own version of a lower function but
> it gives me the same message.
>
> Am I missing something? This seems like it should be pretty
straightforward.
> tia,

You need a special function for triggers. It needs to return "opaque" type
and not take any parameters (in this case). Inside your new function you
will have something like:

BEGIN
  NEW.name := lower(NEW.name);
  RETURN NEW;
END;

Since you need to use NEW and OLD to affect what is happening during your
updates.

See the manuals for an example or http://techdocs.postgresql.org/ for
several.

- Richard Huxton


pgsql-general by date:

Previous
From: Karel Zak
Date:
Subject: Re: [HACKERS] Translators wanted
Next
From: "Robert Treat"
Date:
Subject: RE: trouble with triggers