Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id C68579F9C44 for ; Fri, 7 Sep 2007 11:56:11 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 25443-04 for ; Fri, 7 Sep 2007 11:51:23 -0300 (ADT) X-Greylist: delayed 00:16:48.832406 by SQLgrey-1.7.5 Received: from gmp-eb-mail-2.sun.com (gmp-eb-mail-2.eu.sun.com [192.18.6.24]) by postgresql.org (Postfix) with ESMTP id 223F99F9BAA for ; Fri, 7 Sep 2007 11:47:37 -0300 (ADT) Received: from fe-emea-09.sun.com (gmp-eb-lb-2-fe3.eu.sun.com [192.18.6.12]) by gmp-eb-mail-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id l87EUgnT027556 for ; Fri, 7 Sep 2007 14:30:46 GMT Received: from conversion-daemon.fe-emea-09.sun.com by fe-emea-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) id <0JO000K0145PAZ00@fe-emea-09.sun.com> (original mail from Julius.Stroffek@Sun.COM) for pgsql-bugs@postgresql.org; Fri, 07 Sep 2007 15:30:42 +0100 (BST) Received: from [129.157.18.88] by fe-emea-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTPSA id <0JO0008N35N4MQD0@fe-emea-09.sun.com> for pgsql-bugs@postgresql.org; Fri, 07 Sep 2007 15:30:40 +0100 (BST) Date: Fri, 07 Sep 2007 16:29:44 +0200 From: Julius Stroffek Subject: 'on insert do instead' rule with a where clause responds 'INSERT 0 0' To: pgsql-bugs@postgresql.org Message-id: <46E16058.4070602@Sun.COM> MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_x2f0PT5Htt/PTNpUZqOanA)" User-Agent: Thunderbird 1.5.0.8 (X11/20061204) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/47 X-Sequence-Number: 18274 This is a multi-part message in MIME format. --Boundary_(ID_x2f0PT5Htt/PTNpUZqOanA) Content-type: multipart/alternative; boundary="Boundary_(ID_MM0Qfg2qW15/K5Vqo4cyfA)" --Boundary_(ID_MM0Qfg2qW15/K5Vqo4cyfA) Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7BIT Hi, Attached is the example script 'repro.sql' which creates two relations tab1 and tab2. It also creates a rule on tab1 which simply does insert into tab2. The insert statement into tab1 is executed afterwards. It responds with 'INSERT 0 1'. However if I would create the same rule with the where clause the response to the same insert statement is 'INSERT 0 0'. The output of the script executed through psql is in 'repro.out'. Is this a bug? Is there any reason why the second insert should respond 'INSERT 0 0' instead of 'INSERT 0 1'? Thanks. Cheers Julo --Boundary_(ID_MM0Qfg2qW15/K5Vqo4cyfA) Content-type: text/html; charset=ISO-8859-1 Content-transfer-encoding: 7BIT Hi,

Attached is the example script 'repro.sql' which creates two relations tab1 and tab2. It also creates a rule on tab1 which simply does insert into tab2. The insert statement into tab1 is executed afterwards. It responds with 'INSERT 0 1'. However if I would create the same rule with the where clause the response to the same insert statement is 'INSERT 0 0'. The output of the script executed through psql is in 'repro.out'.

Is this a bug? Is there any reason why the second insert should respond 'INSERT 0 0' instead of 'INSERT 0 1'? Thanks.

Cheers

Julo


--Boundary_(ID_MM0Qfg2qW15/K5Vqo4cyfA)-- --Boundary_(ID_x2f0PT5Htt/PTNpUZqOanA) Content-type: text/plain; name=repro.out Content-transfer-encoding: 7BIT Content-disposition: inline; filename=repro.out CREATE TABLE CREATE TABLE CREATE RULE INSERT 0 1 id ----- 100 (1 row) DROP RULE CREATE RULE DELETE 1 id ---- (0 rows) INSERT 0 0 id ----- 100 (1 row) DROP RULE DROP TABLE DROP TABLE --Boundary_(ID_x2f0PT5Htt/PTNpUZqOanA) Content-type: text/x-sql; name=repro.sql Content-transfer-encoding: 7BIT Content-disposition: inline; filename=repro.sql create table tab1 (id int); create table tab2 (id int); create rule tab1_insert as on insert to tab1 do instead insert into tab2 values (new.id); insert into tab1 values (100); select * from tab2; drop rule tab1_insert on tab1; create rule tab1_insert as on insert to tab1 where 1<2 do instead insert into tab2 values (new.id); delete from tab2; select * from tab2; insert into tab1 values (100); select * from tab2; drop rule tab1_insert on tab1; drop table tab2; drop table tab1; --Boundary_(ID_x2f0PT5Htt/PTNpUZqOanA)--