From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Is it possible to redirect an update/insert/delete to a different table? |
Date: | 2005-11-20 16:17:15 |
Message-ID: | 20051120161715.GA2832@kaufbach.delug.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Andy Ballingall <andy(at)areyoulocal(dot)co(dot)uk> schrieb:
> Hello Peter,
>
> I'm glad it's possible, but I can't see how from the documentation.
>
> Say if I have a table called 'apples' and a table called 'pears'.
>
> What would the rule look like that would remap all updates on apples so that
> they were applied to pears instead?
create rule apples_pears_update as on update to apples do instead update pears set name= NEW.name where id=NEW.id ;
test=# select * from apples ;
id | name
----+------
1 | a
(1 row)
test=# select * from pears ;
id | name
----+------
1 | b
(1 row)
test=# update apples set name = 'c' where id = 1;
UPDATE 1
test=# select * from pears ;
id | name
----+------
1 | c
(1 row)
http://www.postgresql.org/docs/8.1/interactive/rules-update.html
HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
From | Date | Subject | |
---|---|---|---|
Next Message | Andy Ballingall | 2005-11-20 16:37:54 | Re: Is it possible to redirect an update/insert/delete to a different table? |
Previous Message | Andy Ballingall | 2005-11-20 15:40:41 | Re: Is it possible to redirect an update/insert/delete to a different table? |