RULE: ON DELETE doesn't stack deletes - Mailing list pgsql-bugs

From Malcolm Hutty
Subject RULE: ON DELETE doesn't stack deletes
Date
Msg-id 3DDBAEF5.1030401@hutty.com
Whole thread Raw
Responses Re: RULE: ON DELETE doesn't stack deletes
Re: RULE: ON DELETE doesn't stack deletes
List 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@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)

pgsql-bugs by date:

Previous
From: Weber Gerhard
Date:
Subject: version for sun cobalt qube 3
Next
From: "Tamotsu Ebina"
Date:
Subject: Can't start postmaster on Cygwin with local 'ja_JP.EUC