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 8C5F9D7A52 for ; Sun, 20 Nov 2005 12:37:50 -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 98848-09 for ; Sun, 20 Nov 2005 16:37:48 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp-out5.blueyonder.co.uk (smtp-out5.blueyonder.co.uk [195.188.213.8]) by svr1.postgresql.org (Postfix) with ESMTP id 81D06D78F7 for ; Sun, 20 Nov 2005 12:37:47 -0400 (AST) Received: from Eve ([82.43.185.102]) by smtp-out5.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Sun, 20 Nov 2005 16:38:39 +0000 Reply-To: From: Andy Ballingall To: "'Andreas Kretschmer'" , Subject: Re: Is it possible to redirect an update/insert/delete to a different table? Date: Sun, 20 Nov 2005 16:37:54 -0000 Organization: Areyoulocal Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook, Build 11.0.5510 Thread-Index: AcXt7o/F9v+KhrkhQ9GgPGceVyiPpgAAKmzQ In-Reply-To: <20051120161715.GA2832@kaufbach.delug.de> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Message-ID: X-OriginalArrivalTime: 20 Nov 2005 16:38:39.0843 (UTC) FILETIME=[DC923330:01C5EDF0] 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/172 X-Sequence-Number: 23423 Hi Andreas, The rule you've given only works for an update which changes the name. If I do another update which changed the colour instead of the name, = that rule wouldn't do the right thing. Instead, I'm looking for something which, with a single 'rule' (or = whatever the mechanism ends up being), intercepts *any* update on apples, and = applies the changes to the pears table instead, as if the only change that = occurred was a change of table name. I can achieve this in the application which generates the sql commands, = but someone else suggested it was possible with rules, but it may not be the case. Thanks! Andy -----Original Message----- From: pgsql-sql-owner@postgresql.org = [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Andreas Kretschmer Sent: 20 November 2005 16:17 To: pgsql-sql@postgresql.org Subject: Re: [SQL] Is it possible to redirect an update/insert/delete to = a different table? Andy Ballingall schrieb: > Hello Peter, >=20 > I'm glad it's possible, but I can't see how from the documentation. >=20 > Say if I have a table called 'apples' and a table called 'pears'. >=20 > 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=3D NEW.name where id=3DNEW.id ; test=3D# select * from apples ; id | name ----+------ 1 | a (1 row) test=3D# select * from pears ; id | name ----+------ 1 | b (1 row) test=3D# update apples set name =3D 'c' where id =3D 1; UPDATE 1 test=3D# select * from pears ; id | name ----+------ 1 | c (1 row) http://www.postgresql.org/docs/8.1/interactive/rules-update.html HTH, Andreas --=20 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=B0, E = 13.56889=B0 ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend --=20 No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.362 / Virus Database: 267.13.4/176 - Release Date: = 20/11/2005