Re: Question on setting up trigger.
От | Albert REINER |
---|---|
Тема | Re: Question on setting up trigger. |
Дата | |
Msg-id | 20010104214504.A1728@frithjof обсуждение исходный текст |
Ответ на | Question on setting up trigger. (Alan Young <alany@idiglobal.com>) |
Список | pgsql-novice |
Saluton, On Tue, Jan 02, 2001 at 09:38:52AM -0700, Alan Young wrote: > I have the following table: > > CREATE TABLE category ( > id int NOT NULL DEFAULT nextval('_base_id_seq'::text) PRIMARY > KEY, > parentid int REFERENCES category ( id ) > name text, > ); > ... > CREATE FUNCTION "move_catparent" (int4 ) > RETURNS int4 > AS 'UPDATE category > SET parentid = ( SELECT parentid FROM category WHERE id = $1 ) > WHERE parentid = $1; > SELECT 1 AS RESULT' > LANGUAGE 'SQL'; I myself don't know much about triggers, but I think you need: create trigger <trigger name> before delete on category for each row execute procedure move_catparent(old.id); On the other hand, I suppose that a rule might be the better option. I don't know much about this, so don't take this at face value. Albert. > > As it stands, I have to do the following when deleting a category: > > SELECT move_catparent( <id of category being deleted> ); > DELETE FROM category WHERE id=<id of category being deleted>; > ... -- -------------------------------------------------------------------------- Albert Reiner <areiner@tph.tuwien.ac.at> Deutsch * English * Esperanto * Latine --------------------------------------------------------------------------
В списке pgsql-novice по дате отправления: