Re: RULES - Mailing list pgsql-sql

From Martín Marqués
Subject Re: RULES
Date
Msg-id 01052210440603.28396@bugs
Whole thread Raw
In response to RULES  ("J.Fernando Moyano" <txinete@wanadoo.es>)
Responses Re: RULES  ("Ross J. Reedstrom" <reedstrm@rice.edu>)
List pgsql-sql
On Mar 22 May 2001 20:19, J.Fernando Moyano wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> Well ... i'm testing carefully the two rules ==>
>
> CREATE RULE piezas_add AS
>          ON insert TO piezas
>          DO update materia_prima set usadas=(usadas+1)
>          where n_material=new.n_material;
>
> CREATE RULE piezas_delete AS
>          ON delete TO piezas
>          DO update materia_prima set usadas=(usadas-1)
>          where n_material=old.n_material;
>
> Inserting is OK.
> Deleting is broken if it deletes more than one row. The rule is executed
> only one time each delete command, and not one time each deleted row.
>
> It's this OK ??? Am i wrong ???
> It's a "feature" ??  ;-)

That's the right behaviour!
Each time you do a delete, besides the delete, it will execute the update....
If more then one row is deletes, update.... gets executed only once.

You'll have to do more advance programing there. See if count(*) can help you 
in any way.
I see you have to update usadas=(usadas-1). Try something like:

usadas=(usadas-(select count(*) from piezas WHERE condition_delete) )

Saludos... :-)

-- 
Cualquiera administra un NT.
Ese es el problema, que cualquiera administre.
-----------------------------------------------------------------
Martin Marques                  |        mmarques@unl.edu.ar
Programador, Administrador      |       Centro de Telematica                      Universidad Nacional
        del Litoral
 
-----------------------------------------------------------------


pgsql-sql by date:

Previous
From: "J.Fernando Moyano"
Date:
Subject: RULES
Next
From: Alexander Dederer
Date:
Subject: Re: timestamp bug