Re: ON DELETE rule

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "J(dot)Fernando Moyano" <txinete(at)wanadoo(dot)es>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ON DELETE rule
Date: 2001-04-01 19:34:55
Message-ID: 446.986153695@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"J.Fernando Moyano" <txinete(at)wanadoo(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Kings-Lynne 2001-04-02 01:31:43 RE: [HACKERS] Error in the date field (with NULL value...).Thanks!
Previous Message Stef Telford 2001-04-01 17:21:43 Re: Trigger Function and Html Output