pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Svenn Helge Grindhaug <svenn@ii.uib.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: Rule problem
Date: Thu, 13 Jun 2002 10:36:00 -0400
Message-ID: <19317.1023978960@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.SOL.4.44.0206131208300.15638-100000@buksbom.ii.uib.no>
References: <Pine.SOL.4.44.0206131208300.15638-100000@buksbom.ii.uib.no>

Svenn Helge Grindhaug <svenn@ii.uib.no> writes:
> create rule a_delete as
> on delete to a do
> delete from b where id1 = old.id1;

> create rule c_delete as
> on delete to c do
> delete from a where id1 = (select id1 from b where id2 = old.id2);

The a_delete rule is run before the actual "DELETE FROM a" command,
so by the time the latter runs, the b row is gone, and no match exists.

I'd be inclined to think about doing this with foreign keys (set up
for ON DELETE CASCADE) instead of handmade rules.  If you really want
to do it by hand, triggers will probably work better than rules.

			regards, tom lane



view thread (4+ messages)

Message-ID: <19317.1023978960@sss.pgh.pa.us>
Permalink:  ../19317.1023978960@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19317.1023978960@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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, svenn@ii.uib.no
  Subject: Re: Rule problem
  In-Reply-To: <19317.1023978960@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