Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id EBC7AB5DBEE for ; Sun, 9 Oct 2011 17:25:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 43734-04 for ; Sun, 9 Oct 2011 20:25:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sd-17937.dedibox.fr (sd-17937.dedibox.fr [88.191.100.74]) by mail.postgresql.org (Postfix) with ESMTP id EDFE3B5DBE1 for ; Sun, 9 Oct 2011 17:25:47 -0300 (ADT) Received: from [192.168.10.3] (AMontsouris-552-1-106-236.w92-140.abo.wanadoo.fr [92.140.113.236]) by sd-17937.dedibox.fr (Postfix) with ESMTPA id 65B1A3B8EE; Sun, 9 Oct 2011 22:25:47 +0200 (CEST) Subject: Re: [GENERAL] Creating rule for sliding data From: Guillaume Lelarge To: "F. BROUARD / SQLpro" Cc: pgsql-sql Date: Sun, 09 Oct 2011 22:25:47 +0200 In-Reply-To: <4E91F33A.2040908@club-internet.fr> References: <4E917601.4040700@club-internet.fr> <4E91D0BC.2030406@club-internet.fr> <1318180045.2107.2.camel@localhost.localdomain> <4E91F33A.2040908@club-internet.fr> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.3 (3.0.3-1.fc15) Content-Transfer-Encoding: 8bit Message-ID: <1318191947.2120.7.camel@localhost.localdomain> Mime-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201110/10 X-Sequence-Number: 35894 On Sun, 2011-10-09 at 21:17 +0200, F. BROUARD / SQLpro wrote: > Hi, > > Le 09/10/2011 19:07, Guillaume Lelarge a écrit : > > Hi, > > > > On Sun, 2011-10-09 at 18:50 +0200, F. BROUARD / SQLpro wrote: > >> I am answering to myseilf... > >> > >> the good syntax is something like : > >> > >> > >> CREATE RULE R_U_MSR_BEFORE2000x > >> AS > >> ON UPDATE TO T_MESURE_MSR > >> WHERE ( NEW.MSR_DATE< DATE '2000-01-01' ) > >> DO INSTEAD > >> ( > >> -- rows does not change partition : > >> UPDATE T_MESURE_BEFORE2000_MSR > >> SET MSR_ID = NEW.MSR_ID, > >> MSR_DATE = NEW.MSR_DATE, > >> MSR_MESURE = NEW.MSR_MESURE > >> WHERE ( OLD.MSR_DATE< DATE '2000-01-01' ); > >> -- rows does change partition (first INSERT NEWs then DELETE OLDs) > >> INSERT INTO T_MESURE_MSR > >> SELECT MSR_ID, > >> MSR_DATE, > >> MSR_MESURE > >> FROM NEW > >> WHERE NOT ( OLD.MSR_DATE< DATE '2000-01-01' ); ; > >> DELETE FROM T_MESURE_MSR > >> WHERE MSR_ID = OLD.MSR_ID > >> AND MSR_DATE = OLD.MSR_DATE > >> AND MSR_MESURE = OLD.MSR_MESURE > >> AND NOT ( OLD.MSR_DATE< DATE '2000-01-01' ); > >> ); > >> > >> The problem is nowhere in the doc there is a mention where much more > >> than one commande must be place into brackets ! > >> > > > > As a matter of fact, it does: > > > > CREATE [ OR REPLACE ] RULE name AS ON event > > TO table [ WHERE condition ] > > DO [ ALSO | INSTEAD ] { NOTHING | command | ( command ; command ... ) } > > > > ^ ^ > > | | > > See -----------------------------------------+------------------------ > > > > Extract from > > http://www.postgresql.org/docs/9.1/interactive/sql-createrule.html > > > > > > Please give a real example instead of copying the doc that I have read a > lot ! > > I am not so stupid to have post this topic without having try many > syntaxes wich does not works ! > I don't think you're stupid. You said the doc was wrong, and I answered you it wasn't. But I understand it didn't help you solve your issue... Anyway, if you gave us the error message, it would be easier to answer you. Here is the error message I get: ERROR: relation "new" does not exist LINE 18: FROM NEW ^ And actually, you can't use "FROM NEW". And this: INSERT INTO T_MESURE_MSR SELECT MSR_ID, MSR_DATE, MSR_MESURE FROM NEW WHERE NOT ( OLD.MSR_DATE < DATE '2000-01-01' ) has no meaning at all in PostgreSQL. -- Guillaume http://blog.guillaume.lelarge.info http://www.dalibo.com