Re: Need your help
От | Jan Wieck |
---|---|
Тема | Re: Need your help |
Дата | |
Msg-id | 200102261714.MAA03268@jupiter.jw.home обсуждение исходный текст |
Ответ на | Re: Need your help (Jie Liang <jliang@ipinc.com>) |
Список | 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 по дате отправления: