"J.Fernando Moyano" <[EMAIL PROTECTED]> 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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to