Re: Need your help

From: Jan Wieck <janwieck(at)Yahoo(dot)com>
To: Jie Liang <jliang(at)ipinc(dot)com>
Cc: Jyotsna Kypa <jkypa(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Need your help
Date: 2001-02-26 17:14:18
Message-ID: 200102261714.MAA03268@jupiter.jw.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)Yahoo(dot)com #

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Qiqi Dong 2001-02-26 17:18:12 Re: Function to return recordset
Previous Message Stephan Szabo 2001-02-26 17:06:57 Re: conversion