Re: trigger on table
От | Karel Zak |
---|---|
Тема | Re: trigger on table |
Дата | |
Msg-id | 20020214134318.A8046@zf.jcu.cz обсуждение исходный текст |
Ответ на | trigger on table ("Graham Vickrage" <graham@digitalplanit.com>) |
Ответы |
Re: trigger on table
|
Список | pgsql-sql |
On Thu, Feb 14, 2002 at 12:17:02PM -0000, Graham Vickrage wrote: > I am trying to create a trigger on a table that simply sets the last_updated > field when any updates are made to that table. > > I have tried the following: - > > CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS ' > BEGIN > UPDATE item SET last_updated = now(); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > RETURN OLD; > END;' LANGUAGE 'plpgsql'; > > CREATE TRIGGER item_last_updated AFTER UPDATE ON item ^^^^^^^ > FOR EACH ROW EXECUTE PROCEDURE set_item_last_updated(); > > When I try to execute this it hangs and postmaster eventually runs out of > memory. You create trigger on update and inside this trigger you do update again. It's cycle... > Is there a way to do it just using sql not plpsql? It works with PL/SQL, try: CREATE FUNCTION set_item_last_updated () RETURNS OPAQUE AS ' BEGIN NEW.last_updated := ''now''; RETURN NEW; END; ' LANGUAGE 'plpgsql'; CREATE TRIGGER item_last_updated BEFORE UPDATE ON itemFOR EACH ROW EXECUTE PROCEDURE set_item_last_updated (); Karel -- Karel Zak <zakkr@zf.jcu.cz>http://home.zf.jcu.cz/~zakkr/C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
В списке pgsql-sql по дате отправления: