Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C17C6632C19 for ; Mon, 26 Jul 2010 04:50:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 33631-09 for ; Mon, 26 Jul 2010 07:50:47 +0000 (UTC) X-Greylist: delayed 00:09:20.431718 by SQLgrey-1.7.6 Received: from wikingerlegenden.de (static.154.214.46.78.clients.your-server.de [78.46.214.154]) by mail.postgresql.org (Postfix) with ESMTP id 37816632B89 for ; Mon, 26 Jul 2010 04:50:47 -0300 (ADT) Received: from [192.168.23.242] (static.154.214.46.78.clients.your-server.de [78.46.214.154]) (authenticated bits=0) by wikingerlegenden.de (8.14.2/8.14.2) with ESMTP id o6Q7fNns037304; Mon, 26 Jul 2010 09:41:23 +0200 (CEST) (envelope-from foo@meisterderspiele.de) Message-ID: <4C4D3C23.2090804@meisterderspiele.de> Date: Mon, 26 Jul 2010 09:41:23 +0200 From: =?ISO-8859-1?Q?Torsten_Z=FChlsdorff?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.8.1.24) Gecko/20100228 Thunderbird/2.0.0.24 Mnenhy/0.7.5.0 MIME-Version: 1.0 To: Dmitriy Igrishin , pgsql-sql@postgresql.org Subject: Re: [TRIGGER] Returning values from BEFORE UPDATE trigger, without using them References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 201007/103 X-Sequence-Number: 34416 Hey Dmitriy, thanks for your reply. > I think, its would be better to use rule on update instead of the trigger > in such case as you. I've played the whole weekend with the rule-system, but it didn't work for my case. I have a dynamic trigger, which takes cares about revision of rows for every table, it is called from. It looks like that: CREATE OR REPLACE FUNCTION versionizeContent() RETURNS TRIGGER AS $$ BEGIN /* add new version in central register and insert new row */ NEW.revision := addContentRevision (OLD.content_id, OLD.revision, sessval('user_id')::int)); EXECUTE 'INSERT INTO ' || quote_ident(TG_TABLE_NAME) || ' SELECT (' || QUOTE_LITERAL(NEW) || '::' || quote_ident(TG_TABLE_NAME) ||').*' ; RETURN NULL; END; $$ LANGUAGE 'plpgsql' VOLATILE; Even if i drop the dynamic INSERT-Part and write it for every relation, i wasn't able to figured out how to manipulate the NEW-Record. The best i tried so far was: CREATE RULE "versionize" AS ON UPDATE TO templates DO INSTEAD ( SELECT addContentRevision (OLD.content_id, OLD.revision, sessval('user_id')::int) INTO NEW.revision; INSERT INTO templates SELECT NEW.* RETURNING *; ); But an Updates ends with the ERROR: "ERROR: schema "*NEW*" does not exist" Has anyone a hint how to manipulate the NEW record within an RULE? Thanks, Torsten