Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6D390B5DC0A for ; Wed, 21 Sep 2011 12:49:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 22263-03 for ; Wed, 21 Sep 2011 15:49:52 +0000 (UTC) X-Greylist: delayed 00:17:45.400807 by SQLgrey-1.8.0-rc2 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id E66D8B5DC22 for ; Wed, 21 Sep 2011 12:49:51 -0300 (ADT) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1R6OmK-00033s-C7 for pgsql-general@postgresql.org; Wed, 21 Sep 2011 08:32:04 -0700 Date: Wed, 21 Sep 2011 08:32:04 -0700 (PDT) From: jablonov To: pgsql-general@postgresql.org Message-ID: <1316619124366-4826781.post@n5.nabble.com> In-Reply-To: <86d227fd0708110043q341a2908q67e87570bca89492@mail.gmail.com> References: <86d227fd0708110043q341a2908q67e87570bca89492@mail.gmail.com> Subject: Re: Trigger Procedure Error: NEW used in query that is not in a rule MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.767 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201109/682 X-Sequence-Number: 180040 Here is other option using functionality of ROW and EXECUTE USING. IF EXISTS(SELECT relname FROM pg_class WHERE relname = tablename) THEN sql := 'INSERT INTO ' || tablename || ' VALUES (($1).*)'; ELSE sql := 'INSERT INTO ' || tablexception || ' VALUES (($1).*)'; END IF; tablerow := ROW(NEW.*)::public.measurement; EXECUTE sql USING tablerow; RETURN new; -- View this message in context: http://postgresql.1045698.n5.nabble.com/Trigger-Procedure-Error-NEW-used-in-query-that-is-not-in-a-rule-tp1886197p4826781.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.