Re: Rules and actions involving multiple rows

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: jasongodden(at)optushome(dot)com(dot)au
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rules and actions involving multiple rows
Date: 2003-07-09 23:22:50
Message-ID: 3F0CA3CA.907@openratings.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jason Godden wrote:

>Hi All,
>
>Just have a quick question regarding rules:
>
>In the past I've always used triggers to fire before or after events however I
>see that the same thing can be achieved through rules (for logging etc...) so
>I created a rule which fires on update (not DO INSTEAD) however it only seems
>to work for a single row - whereas the triggers work for all rows updated in
>a transaction. Is this correct and if so I presume I should be sticking to
>triggers if I want this kind of behaviour?
>
>Rgds,
>
>
Hmmm... Works for me... :

testdb=# create table x (x int);
CREATE TABLE
testdb=# create table old_x (x int);
CREATE TABLE
testdb=# insert into x values (1);
INSERT 17204 1
testdb=# insert into x values (2);
INSERT 17205 1
testdb=# create rule xup as on update to x do insert into old_x values
(old.*);
CREATE RULE
testdb=# update x set x=0;
UPDATE 2
testdb=# select * from old_x;
x
---
1
2
(2 rows)

Or were you talking about something else?

Dima

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roderick A. Anderson 2003-07-09 23:38:32 psql only on client (RPM)
Previous Message Ian Barwick 2003-07-09 23:03:45 Re: IIRC + intervals + and other things