From: Jens Hartwig <jens.hartwig@t-systems.de>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: AW: Problems with RULE
Date: Wed, 7 Mar 2001 08:18:19 +0100
Message-ID: <000d01c0a6d6$c9976bd0$c10ac98a@0000864A433A> (raw)
In-Reply-To: <7272.983909452@sss.pgh.pa.us>
JH:
> > [...]
> > I tried to implement the following rule: if someone wants to delete a
record
> > from a table t_xyz (id integer, deleted boolean) the record should get a
> > delete-flag (deleted = true). When this "pre-deleted" record is deleted
for
> > the next time it should be physically deleted from the database.
> > [...]
TL:
> In my experience, anything you want to do that can be expressed as
> an operation or condition on an individual target tuple of an
> INSERT/UPDATE/DELETE is best done in a trigger, for reasons of both
> performance and understandability. Rules are good for things that
> involve conditions on multiple tuples.
> [...]
I am afraid, that I do not really understand this: if I insert one record in
a view there also is only ONE tuple involved, isn't it? By the way, I admit
that my example is not really useful :-) It should only demonstrate the use
of rules for the book I am writing on.
Further I do not understand the following:
> You'd probably have better luck doing this with a trigger. With this
> rule, the DELETE query expands into two operations, which can
> be written
> as:
>
> UPDATE t_xyz SET deleted = true
> WHERE id IN
> (SELECT old.id FROM t_xyz old WHERE old.id = 1 AND
> old.deleted = false);
>
> DELETE FROM t_xyz WHERE id = 1 AND NOT (deleted = false);
What would have happened, if I executed an unconditional DELETE?
=> DELETE FROM t_xyz;
Which statement would have been generated by PostgreSQL in this case?
Best Regards, Jens
-----------------------------------------------------
T-Systems
Projektleiter
debis Systemhaus GEI GmbH
Hausanschrift: Eichhornstraße 3, 10785 Berlin
Postanschrift: 10785 Berlin
Telefon: (004930) 25 54-32 82
Telefax: (004930) 25 54-31 87
Mobiltelefon: (0170) 167 26 48
E-Mail: jens.hartwig@t-systems.de
Internet: http://www.t-systems.de
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: jens.hartwig@t-systems.de, tgl@sss.pgh.pa.us
Subject: Re: Problems with RULE
In-Reply-To: <000d01c0a6d6$c9976bd0$c10ac98a@0000864A433A>
References: <7272.983909452@sss.pgh.pa.us> <000d01c0a6d6$c9976bd0$c10ac98a@0000864A433A>
* 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