Re: A "cascade on delete" constraints deletes AFTER the source is gone??

From: Vitaly Belman <vitalyb(at)gmail(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: A "cascade on delete" constraints deletes AFTER the source is gone??
Date: 2004-12-20 07:56:35
Message-ID: fa96e3c604121923566cc3918f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It's a bit complex.

I have two tables. "Books" and "Book_Authors" (which links between
book_id and author_id).
Book_authors has a foreign key on book_id to the Books table. On key
violation it is set to delete the rows (if a book is deleted, it
should't be linked to any authors).

In Book_Authors I also have a trigger on DELETE. When a book is
unlinked from an author, then the author vote_count should be reduced
(as the author vote_count is the sum of all votes of his books).

The problem is that when a book is deleted and then the trigger tried
to get the number of it votes, it returns NULL, as the book is already
gone and so its data. If it was a simple matter of triggers I could
play with BEFORE/AFTER, but since it is constraints issue, it seems to
be all happening AFTER the deletion.

On Sun, 19 Dec 2004 12:23:09 -0700, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
> On Sun, Dec 19, 2004 at 03:20:19PM +0200, Vitaly Belman wrote:
>
> > I noticed that when you do a constraint and tell it "cascade on
> > delete", it will do so only AFTER that the source is deleted. Can I
> > tell it somehow to cascade BEFORE the source is gone?
>
> What problem are you trying to solve?
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>

--
ICQ: 1912453
AIM: VitalyB1984
MSN: tmdagent(at)hotmail(dot)com
Yahoo!: VitalyBe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message JM 2004-12-20 09:32:25 Re: readline configure error again
Previous Message Jim C. Nasby 2004-12-20 06:18:05 pgjob registered on pgFoundary