Skip site navigation (1) Skip section navigation (2)

Re: CREATE RULE ignored, what did I do wrong

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: andrew(at)pillette(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CREATE RULE ignored, what did I do wrong
Date: 2004-09-11 06:42:23
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
andrew(at)pillette(dot)com writes:
> Foreign-key constraints:
>     "$1" FOREIGN KEY (smoothing_id) REFERENCES smoothing_algorithm(smoothing_id) ON UPDATE CASCADE ON DELETE CASCADE
> Rules:
>     del_smoothed_rank_episode AS ON DELETE TO smoothed_rank_episode
> WHERE (NOT old.is_deleted) DO INSTEAD ...

The DELETE commands generated by the foreign key ON DELETE CASCADE will
get rewritten by your ON DELETE rule.  You probably do not want to do
this; or at least not make it an INSTEAD rule.

There has been some debate in the past about whether rules should be
able to break foreign-key constraints, but I tend to class it as a
"you should know what you're doing" feature.  Preventing this kind
of error would inevitably result in a serious reduction of the power
of the rule feature.

			regards, tom lane

In response to

pgsql-sql by date

Next:From: Michael GlaesemannDate: 2004-09-11 12:57:23
Previous:From: Michalis KabrianisDate: 2004-09-11 06:22:36
Subject: Re: [SQL] PL/pgSQL Function Problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group