pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: J.Fernando Moyano <txinete@wanadoo.es>
Cc: pgsql-sql@postgresql.org
Subject: Re: ON DELETE rule
Date: Sun, 01 Apr 2001 15:34:55 -0400
Message-ID: <446.986153695@sss.pgh.pa.us> (raw)
In-Reply-To: <01040110093800.01615@txino.mikasa.eh>
References: <01040110093800.01615@txino.mikasa.eh>

"J.Fernando Moyano" <txinete@wanadoo.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



view thread (2+ messages)

Message-ID: <446.986153695@sss.pgh.pa.us>
Permalink:  ../446.986153695@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/446.986153695@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, txinete@wanadoo.es
  Subject: Re: ON DELETE rule
  In-Reply-To: <446.986153695@sss.pgh.pa.us>
  References: <01040110093800.01615@txino.mikasa.eh> <446.986153695@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox