Received: from maia.hub.org (maia-4.hub.org [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C70D5632B92 for ; Tue, 11 May 2010 09:42:34 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 79768-03 for ; Tue, 11 May 2010 12:42:27 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id BE65A632509 for ; Tue, 11 May 2010 09:42:27 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.3/8.14.3) with ESMTP id o4BCg85E043251 for ; Tue, 11 May 2010 09:42:08 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.3/8.14.3/Submit) id o4BCZQkC033746 for pgsql-sql@postgresql.org; Tue, 11 May 2010 09:35:26 -0300 (ADT) (envelope-from news) From: =?ISO-8859-15?Q?Torsten_Z=FChlsdorff?= X-Newsgroups: pgsql.sql Subject: [Trigger] Help needed with NEW.* and TG_TABLE_NAME Date: Tue, 11 May 2010 14:31:09 +0200 Organization: A noiseless patient Spider Lines: 46 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 11 May 2010 12:35:36 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="AnkPUomeHXvuN7UdHvIkog"; logging-data="28014"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WK3fo41to1PhqKBjEHbn9" 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 Cancel-Lock: sha1:T3Yj2D2HvavRdMIKyStP2nn1rS8= To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-5 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/38 X-Sequence-Number: 34086 Hello, i have a problem with a trigger written in pl/pgsql. It looks like this: CREATE OR REPLACE FUNCTION versionize() RETURNS TRIGGER AS $$ BEGIN NEW.revision := addContentRevision (OLD.content_id, OLD.revision); /* not working line, just a stub: EXECUTE 'INSERT INTO ' || TG_TABLE_NAME || ' SELECT $1 ' USING NEW; */ RETURN NULL; END; $$ LANGUAGE 'plpgsql' VOLATILE; The function should be used at different tables and is invoked before UPDATEs. Everything what happens is the function call of addContentRevision. After this call all data (with the updated revision column) should be stored in the table as a new row. My problem: the aim-table is not static. It's just always the table which invoked the trigger. The trigger itself could be called at many tables. I've tried some other ways of expressing the INSERT but nothing worked: - 'INSERT INTO ' || TG_TABLE_NAME || ' SELECT NEW.*' - INSERT INTO TG_TABLE_NAME SELECT NEW.* - EXECUTE 'INSERT INTO ' || TG_TABLE_NAME USING NEW; Do you have any hints? Greetings from Germany, Torsten -- http://www.dddbl.de - ein Datenbank-Layer, der die Arbeit mit 8 verschiedenen Datenbanksystemen abstrahiert, Queries von Applikationen trennt und automatisch die Query-Ergebnisse auswerten kann.