Re: RULES

From: Martín Marqués <martin(at)bugs(dot)unl(dot)edu(dot)ar>
To: "J(dot)Fernando Moyano" <txinete(at)wanadoo(dot)es>, pgsql-sql(at)postgresql(dot)org
Subject: Re: RULES
Date: 2001-05-22 07:44:06
Message-ID: 01052210440603.28396@bugs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)unl(dot)edu(dot)ar
Programador, Administrador | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------

In response to

  • RULES at 2001-05-22 17:19:00 from J.Fernando Moyano

Responses

  • Re: RULES at 2001-05-22 14:53:55 from Ross J. Reedstrom

Browse pgsql-sql by date

  From Date Subject
Next Message J.Fernando Moyano 2001-05-22 09:56:38 RULES
Previous Message Bruce Momjian 2001-05-22 04:15:56 Re: how to check presence of a function and set permissions?