Skip site navigation (1) Skip section navigation (2)

Re: Creating Functions & Triggers

From: Markus Bertheau <twanger(at)bluetwanger(dot)de>
To: Kevin Lohka <klohka(at)aboutfacedata(dot)ab(dot)ca>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Creating Functions & Triggers
Date: 2004-03-21 09:37:53
Message-ID: 1079861873.2085.1.camel@yarrow.bertheau.de (view raw or flat)
Thread:
Lists: pgsql-novice
В Сбт, 20.03.2004, в 23:33, Kevin Lohka пишет:
> Hello everyone, I'm new to creating functions & triggers on postgresql 
> and am having trouble creating a trigger to update a record with the 
> modification date and the current user.
> 
> My code is below, but doesn't work.  It hangs psql when I attempt to 
> modify the record.  The function and trigger are created successfully.
> 
> CREATE FUNCTION email_mod_date() RETURNS OPAQUE AS '
>    BEGIN
>          UPDATE email SET  m_date = current_date, m_by_user = 
> current_user
>          WHERE id = NEW.id;
> 
>    RETURN NULL;
>    END;
> 'LANGUAGE 'plpgsql';
> 
> 
> 
> CREATE TRIGGER email_mod_date
> AFTER UPDATE
> ON email
> FOR EACH ROW
> EXECUTE PROCEDURE email_mod_date();

The trigger is probably recursively being called.
http://www.postgresql.org/docs/current/static/triggers.html#TRIGGER-DEFINITION

-- 
Markus Bertheau <twanger(at)bluetwanger(dot)de>


In response to

Responses

pgsql-novice by date

Next:From: Mihai TanasescuDate: 2004-03-21 11:58:03
Subject: Simple list tables question
Previous:From: V i s h a l Kashyap @ [Sai Hertz And Control Systems]Date: 2004-03-21 05:23:31
Subject: Re: Creating Functions & Triggers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group