Re: RULES

Поиск
Список
Период
Сортировка
От Martín Marqués
Тема Re: RULES
Дата
Msg-id 01052210440603.28396@bugs
обсуждение исходный текст
Ответ на RULES  ("J.Fernando Moyano" <txinete@wanadoo.es>)
Ответы Re: RULES
Список 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 по дате отправления:

Предыдущее
От: "J.Fernando Moyano"
Дата:
Сообщение: RULES
Следующее
От: Alexander Dederer
Дата:
Сообщение: Re: timestamp bug