pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
ON DELETE rule 2+ messages / 2 participants [nested] [flat]
* ON DELETE rule @ 2001-04-01 08:09 J.Fernando Moyano <txinete@wanadoo.es> 0 siblings, 1 reply; 2+ messages in thread From: J.Fernando Moyano @ 2001-04-01 08:09 UTC (permalink / raw) To: pgsql-sql I'm trying to do something like this: CREATE RULE piezas_delete AS ON delete TO piezas DO update materia_prima set usadas=(usadas-1) where n_material=old.n_material; The rule is created. OK .... but the action doesn't run like it's supossed. ¿What is wrong? Is "old" usable with "ON DELETE" rules ??? I think delete action its performed AFTER rule action .... ¿OK? So ... it's possible to access field values of delete affectted registers? -- Fernando Moyano Frase del día: -------------- No hay cita. Solo son imaginaciones tuyas!!. (*) SymeX ==> http://symex.lantik.com (*) WDBIL ==> http://wdbil.sourceforge.net (*) Informate sobre LINUX en http://www.linux.org ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: ON DELETE rule @ 2001-04-01 19:34 Tom Lane <tgl@sss.pgh.pa.us> parent: J.Fernando Moyano <txinete@wanadoo.es> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2001-04-01 19:34 UTC (permalink / raw) To: J.Fernando Moyano <txinete@wanadoo.es>; +Cc: pgsql-sql "J.Fernando Moyano" <txinete@wanadoo.es> writes: > I'm trying to do something like this: > CREATE RULE piezas_delete AS > ON delete TO piezas > DO update materia_prima set usadas=(usadas-1) > where n_material=old.n_material; > The rule is created. OK .... but the action doesn't run like it's supossed. This will almost certainly not do what you intended, at least not for cases in which a DELETE deletes multiple rows from piezas. The rule creates an additional query that will be run once for each DELETE query against piezas. You appear to be envisioning one firing per tuple deleted. I'd recommend doing the UPDATE inside a trigger instead. That approach will operate in the way you envision. regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-04-01 19:34 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2001-04-01 08:09 ON DELETE rule J.Fernando Moyano <txinete@wanadoo.es> 2001-04-01 19:34 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox