Re: Table rule does not work! - Mailing list pgsql-general

From Tom Lane
Subject Re: Table rule does not work!
Date
Msg-id 5084.983579655@sss.pgh.pa.us
Whole thread Raw
In response to Table rule does not work!  ("omid omoomi" <oomoomi@hotmail.com>)
List pgsql-general
"omid omoomi" <oomoomi@hotmail.com> writes:
> when I insert into table tk ,I expect to have table tu updated... but it is
> not! although  there is no error message with it, the table tu remains
> unchanged.

I cannot duplicate a problem with that rule, using either 7.0.2 or
current sources:

play=> create table tk(k1 int, k2 int, k3 int, k4 int, k5 int);
CREATE
play=> create table tu(u1 int, u2 int, u3 int);
CREATE
play=> insert into tu values (1,1,1);
INSERT 745816 1
play=> insert into tu values (2,2,2);
INSERT 745817 1
play=> create rule tk_rule1 as on insert to tk do
play-> update tu
play-> set u1 = u1 + (new.k2 - new.k1) ,
play-> u2 = u2 + (new.k3 + new.k4 )
play-> where tu.u3 = new.k5 ;
CREATE 745818 1
play=> insert into tk values (7,22,42,17,2);
INSERT 745819 1
play=> select * from tk;
 k1 | k2 | k3 | k4 | k5
----+----+----+----+----
  7 | 22 | 42 | 17 |  2
(1 row)

play=> select * from tu;
 u1 | u2 | u3
----+----+----
  1 |  1 |  1
 17 | 61 |  2
(2 rows)

play=>

Either you made a mistake, or there's some other factor you haven't
mentioned.

            regards, tom lane

pgsql-general by date:

Previous
From: "Dan Harrington"
Date:
Subject: Error message on pg_dumpall
Next
From: Lincoln Yeoh
Date:
Subject: Re: Re: serial properties