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

BUG #1676: Statment order in rules

From: "Olleg Samoylov" <olleg(at)mipt(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1676: Statment order in rules
Date: 2005-05-19 13:30:12
Message-ID: 20050519133012.75B4FF0B17@svr2.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-bugs
The following bug has been logged online:

Bug reference:      1676
Logged by:          Olleg Samoylov
Email address:      olleg(at)mipt(dot)ru
PostgreSQL version: 7.4.7
Operating system:   on x86_64-pc-linux-gnu, compiled by GCC x86_64-linux-gcc
(GCC) 3.3.5 (Debian 1:3.3.5-12)
Description:        Statment order in rules
Details: 

-- Here example for delete rule, but for update rule bug arised also. 
-- This is simplified example from working database.
-- create tables
-- counter
create table c (c integer);
insert into c values (0);
-- private table
create table a (a integer);
-- public view
create view v as select a from a;

-- create worked rules, for example
create rule insert_last as on insert to v do instead (update c set
c=c+1;insert into a values (new.a));
create rule delete_last as on delete to v do instead (update c set
c=c-1;delete from a where a=old.a);

insert into v values (0);
select * from a;
-- 1 row
select * from c;
-- 1

delete from v where a=0;
select * from a;
-- 0 rows
select * from c;
-- 0, Okey

-- now change order of statment
drop rule insert_last on v;
drop rule delete_last on v;
create rule insert_first as on insert to v do instead (insert into a values
(new.a);update c set c=c+1);
create rule delete_first as on delete to v do instead (delete from a where
a=old.a;update c set c=c-1);

insert into v values (0);
select * from a;
-- 1 row
select * from c;
-- 1, Ok

delete from v where a=0;
select * from a;
-- 0 row, as expected :-)
select * from c;
-- 1, this is incorrect

Responses

pgsql-bugs by date

Next:From: Neil ConwayDate: 2005-05-19 13:31:41
Subject: Re: BUG #1671: Long interval string representation rejected
Previous:From: DimitarDate: 2005-05-19 12:27:17
Subject: BUG #1675: very slow work

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