Re: functions and triggers

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: functions and triggers
Date: 2002-08-20 21:59:50
Message-ID: 20020820145456.F45900-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 20 Aug 2002, Martin Marques wrote:

> Quoting Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>:
>
> >
> > > The problemas are two:
> > >
> > > 1) when I try to create the trigger, it says that the function doesn't
> > exist.
> > > Why is this happening?
> >
> > You should probably show us what you were trying to do, but I'm going to
> > guess that the function doesn't have the right signature. On
> > current versions, Trigger functions should return opaque and take no
> > arguments (any arguments given on the create trigger line are passed
> > in a different fashion).
>
> I have this function which works OK.
>
> CREATE FUNCTION ahora (integer) RETURNS integer AS '
> UPDATE usuarios SET tmodif = now()
> WHERE codigo = $1;
> SELECT 1 as RESULT;
> ' LANGUAGE SQL

Trigger functions have no args and return opaque and I don't think you
can use sql language functions, but I'm not sure. Something like:

create function ahora_trigger() returns opaque as '
begin
NEW.tmodif := now();
return NEW;
end;'
language 'plpgsql';

should work as a before update trigger.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Mark Stosberg 2002-08-21 02:15:37 Re: Event recurrence - in database or in application code ????
Previous Message Martin Marques 2002-08-20 21:37:24 Re: functions and triggers