Re: Cascading deletes with rules in 7.0.3: why doesn't this work?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeremy Radlow <jtr(at)sourcerers(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Cascading deletes with rules in 7.0.3: why doesn't this work?
Date: 2001-04-02 15:52:26
Message-ID: 8005.986226746@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Jeremy Radlow <jtr(at)sourcerers(dot)com> writes:
>> In the following example, I'm trying to log all deletions from any of three
>> tables. The only information I'm interested in recording is the index from
>> table A which the deleted row referenced.

> This seems to be a bug.

No, there's no bug. The problem is the weird way you defined the
c_delete rule:

create rule c_delete as
on delete to c do
insert into delete_log (ax)
values ((select ax from b where b.bx = old.bx));

This depends on the assumption that there will be an entry in b that
matches the bx value of the c row being deleted. Unfortunately, when
this delete is fired from an ON CASCADE DELETE from table b, the
relevant row of b is already gone (as far as this transaction is
concerned, anyway). So the subselect yields no rows and you end up
trying to insert a null into delete_log.

Seems to me you want to record the A reference value directly in rows
of C, so that C's delete rule can look the same as B's.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2001-04-02 16:10:51 TODO list
Previous Message Richard Huxton 2001-04-02 15:22:46 Query rewriting: updates