Re: Need your help - Mailing list pgsql-sql

From Jan Wieck
Subject Re: Need your help
Date
Msg-id 200102261714.MAA03268@jupiter.jw.home
Whole thread Raw
In response to Re: Need your help  (Jie Liang <jliang@ipinc.com>)
List pgsql-sql
Jie Liang wrote:
> e.g.
> Try:
>
> CREATE TABLE emp (
>     id int4 primary key,
>     empname text,
>     salary int4,
>     last_date datetime,
>     last_user name);
>
> CREATE FUNCTION emp_stamp () RETURNS OPAQUE AS
>     BEGIN
>    update emp set last_date=''now''::timestamp where id=NEW.id;
>         RETURN NEW;
>     END;
> ' LANGUAGE 'plpgsql';
>
> CREATE TRIGGER emp_stamp BEFORE UPDATE ON emp
>     FOR EACH ROW EXECUTE PROCEDURE emp_stamp();
   Not  sure  if it works this way at all, but the update on emp   table is definitely a wasted scan. And  the
'now'::timestamp  will  be  evaluated at the first function call - never again;   not sure if he wanted that behaviour
either.
       CREATE FUNCTION emp_stamp () RETURNS opaque AS '       BEGIN           new.last_date := now();           RETURN
new;      END;'       LANGUAGE 'plpgsql';
 
   Is the correct trigger for this purpose.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



pgsql-sql by date:

Previous
From: Louis-David Mitterrand
Date:
Subject: Re: Compiling "C" Functions
Next
From: SCAHILL KEVIN
Date:
Subject: SELECT DISTINCT problems