From: Richard Huxton <dev@archonet.com>
To: Jens Hartwig <jens.hartwig@t-systems.de>
Cc: 'PSQL-Sql (E-Mail)' <pgsql-sql@postgresql.org>
Subject: Re: Problems with RULE
Date: Wed, 7 Mar 2001 09:50:26 -0000
Message-ID: <006701c0a6ec$3a60f7e0$1001a8c0@archonet.com> (raw)
References: <000e01c0a6d7$8ad0c0d0$c10ac98a@0000864A433A>
From: "Jens Hartwig" <jens.hartwig@t-systems.de>
> Hello Richard,
>
> this was a very precise analysis - thanks for the effort you made!
Precisely wrong in this case. My mistakes have some of the finest tolerances
in the world. 8-)
> Nevertheless the Tom's explanation of the behaviour in case of views was
> sufficient for me. But still I don't understand the behaviour in my case
...
Yep - thanks Tom (another item for my notebook). I _think_ I understand
Tom's explanation of your case - does this make sense?
You have CREATE RULE r1 ON t_xyz WHERE old.deleted=false ...
So - if you issue "DELETE FROM t_xyz" you'd want two things to happen:
1. where deleted is false set it to true
2. where deleted was true delete the record
So - PG rewrites the query into two parts:
DELETE FROM t_xyz WHERE old.deleted=false
DELETE FROM t_xyz WHERE NOT(old.deleted=false)
Unfortunately, the changes from the first part are visible to the second
part so you end up marking everything for deletion then deleting it.
Of course in your case you were selecting id=1 so it wasn't so obvious.
I think that's what's happening here. Unfortunately, setting DEBUG_PRINT_xxx
doesn't seem to show any detail, do I can't show a trace.
Of course, with a trigger you can have an IF..THEN..ELSE to make sure you
control the order of execution.
- Richard Huxton
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: dev@archonet.com, jens.hartwig@t-systems.de
Subject: Re: Problems with RULE
In-Reply-To: <006701c0a6ec$3a60f7e0$1001a8c0@archonet.com>
References: <000e01c0a6d7$8ad0c0d0$c10ac98a@0000864A433A> <006701c0a6ec$3a60f7e0$1001a8c0@archonet.com>
* 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