From: | Malcolm Hutty <msah-postgres(at)hutty(dot)com> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | RULE: ON DELETE doesn't stack deletes |
Date: | 2002-11-20 15:49:09 |
Message-ID: | 3DDBAEF5.1030401@hutty.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
According to the manual you can stack multiple queries in a RULE:
CREATE RULE name AS ON event
TO object [ WHERE condition ]
DO [ INSTEAD ] action
where action can be:
NOTHING
|
query
|
( query ; query ... )
|
[ query ; query ... ]
This seems to work provided 'query' is not "DELETE"; if it is, only
the first one is executed.
My installation is Postgres 7.2.2, using the binary package shipped in
Redhat 8.0
[malcolm(at)localhost STRUCT]$ uname -sr
Linux 2.4.18-18.8.0
Here is a test case:
CREATE TABLE A
(a_data int);
CREATE TABLE B
(b_data int);
CREATE VIEW V_AB AS
SELECT a_data,b_data FROM A,B;
CREATE RULE R_DEL_AB AS
ON DELETE TO V_AB
DO INSTEAD
(
DELETE FROM A WHERE a_data=OLD.a_data;
DELETE FROM B WHERE b_data=OLD.b_data;
);
INSERT INTO A values (1);
INSERT INTO B values (1);
test=# select * from V_AB;
a_data | b_data
--------+--------
1 | 1
(1 row)
test=#delete from v_ab;
DELETE 0
test=# select * from a;
a_data
--------
(0 rows)
test=# select * from b;
b_data
--------
1
(1 row)
From | Date | Subject | |
---|---|---|---|
Next Message | Hai-Chen Tu | 2002-11-20 17:19:08 | dbmirror bug |
Previous Message | Weber Gerhard | 2002-11-20 08:31:58 | version for sun cobalt qube 3 |