X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A675AD7D23 for ; Sun, 20 Nov 2005 12:38:01 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98679-06 for ; Sun, 20 Nov 2005 16:37:59 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by svr1.postgresql.org (Postfix) with ESMTP id CDC48D7AD3 for ; Sun, 20 Nov 2005 12:37:57 -0400 (AST) Received: from a-kretschmer.de (p54B39330.dip0.t-ipconnect.de [84.179.147.48]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id jAKGbsXD023360 for ; Sun, 20 Nov 2005 17:37:55 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 3.36 #1) id 1EdsGw-00016l-00 for pgsql-sql@postgresql.org; Sun, 20 Nov 2005 17:42:34 +0100 Date: Sun, 20 Nov 2005 17:42:34 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Is it possible to redirect an update/insert/delete to a different table? Message-ID: <20051120164234.GB2832@kaufbach.delug.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[AWL=0.000] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/173 X-Sequence-Number: 23424 Andy Ballingall schrieb: > Hello Jaime, > > I'm still not quite clear. > > Say I have a number of different updates on a table 'apples' in my code, > including: > > UPDATE apples set pips=6 and color='yellow' where id=3; > UPDATE apples set size=10 where id=6; > > What would a rule look like which, when *any* update is attempted on the > apples table, will instead apply the update to a different table - 'pears'. Try it. test=# create table apples (id int, name1 text, name2 text); CREATE TABLE test=# create table pears (id int, name1 text, name2 text); CREATE TABLE test=# create rule apples_pears_update as on update to apples do instead update pears set name1= NEW.name1, name2=NEW.name2 where id=NEW.id ; CREATE RULE test=# insert into apples values (1, 'a', 'a'); INSERT 0 1 test=# insert into pears values (1, 'a', 'a'); INSERT 0 1 test=# test=# update apples set name1='b' where id = 1; UPDATE 1 test=# select * from pears ; id | name1 | name2 ----+-------+------- 1 | b | a (1 row) test=# update apples set name2='c' where id = 1; UPDATE 1 test=# select * from pears ; id | name1 | name2 ----+-------+------- 1 | a | c (1 row) test=# update apples set name1='e', name2='e' where id = 1; UPDATE 1 test=# select * from pears ; id | name1 | name2 ----+-------+------- 1 | e | e (1 row) > > -----Original Message----- Please, no top-posting. 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°