BUG #10006: 'DO INSTEAD UPDATE' error - Mailing list pgsql-bugs

From lucybird@126.com
Subject BUG #10006: 'DO INSTEAD UPDATE' error
Date
Msg-id 20140413145740.15386.4908@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #10006: 'DO INSTEAD UPDATE' error  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      10006
Logged by:          lucybird
Email address:      lucybird@126.com
PostgreSQL version: 9.1.13
Operating system:   ubuntu 12.04 server
Description:

CREATE TABLE dns (
    customer_id integer NOT NULL,
    hits integer,
        primary key (customer_id)
);

CREATE RULE replace_dns AS
    ON INSERT TO dns
    WHERE EXISTS (SELECT 1 FROM dns WHERE dns.customer_id =
new.customer_id)
    DO INSTEAD UPDATE dns
        SET hits = hits + 1
        WHERE  dns.customer_id = new.customer_id;

insert into dns (customer_id, hits) values (1,0);

select * from dns;

customer_id,hits
1,    1

why? hits value must be 0, why 1?

pgsql-bugs by date:

Previous
From: kona ajay
Date:
Subject: cant insert into a post gre sql table...Can u please help in fixing this
Next
From: John R Pierce
Date:
Subject: Re: Fwd: cant insert into a post gre sql table...Can u please help in fixing this