X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 2E88BD1DB0C for ; Wed, 21 Apr 2004 17:19:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 22347-02 for ; Wed, 21 Apr 2004 17:19:56 -0300 (ADT) Received: from fedk0910.ferring.com (fedk0905.ferring.com [213.237.141.20]) by svr1.postgresql.org (Postfix) with ESMTP id D85EDD1D44E for ; Wed, 21 Apr 2004 17:19:53 -0300 (ADT) Received: from fedk0005.Fic.ferring.com (unverified) by fedk0910.ferring.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Wed, 21 Apr 2004 22:05:28 +0200 Received: from ferring.com (10.20.100.63 [10.20.100.63]) by fedk0005.Fic.ferring.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id HJQ4NRD5; Wed, 21 Apr 2004 22:05:42 +0200 Message-ID: <4086D465.1060907@ferring.com> Date: Wed, 21 Apr 2004 13:07:01 -0700 From: Kemin Zhou User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: rule's behavior with join interesting Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200404/214 X-Sequence-Number: 17589 Here I have a very simple case table1 table1_removed anotherTable create or replace RULE rec_remove as ON DELETE TO table1 do insert into table1_remove select old.*, a.acc from old g join anotherTable a on g.acc=a.other_acc; === the parser complained ERROR: relation "*OLD*" does not exist So I used select old.*, a.acc from table1 g join anotherTable a on g.acc=a.other_acc; This worked find. When I run delete on table1, 213 rows. tmp table received 213X213 = 45369 rows. each row is duplicated 213 times. My question: Is it possible to bring in another table in a rule? Where am I wrong in this case. Certainly I don't want that duplications. My table1_removed contain a primary key for the id. The speed of doing the delete is also very slow apparently it has to do N-square inserts. I have very limited information to read on the manual of postgres. Any solution? Kemin ********************************************************************** Proprietary or confidential information belonging to Ferring Holding SA or to one of its affiliated companies may be contained in the message. If you are not the addressee indicated in this message (or responsible for the delivery of the message to such person), please do not copy or deliver this message to anyone. In such case, please destroy this message and notify the sender by reply e-mail. Please advise the sender immediately if you or your employer do not consent to e-mail for messages of this kind. Opinions, conclusions and other information in this message represent the opinion of the sender and do not necessarily represent or reflect the views and opinions of Ferring. **********************************************************************