Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4368E6326BB for ; Mon, 10 May 2010 06:42:20 -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 58074-03 for ; Mon, 10 May 2010 09:42:12 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id 3BA27633333 for ; Mon, 10 May 2010 06:42:13 -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 o4A9g8jj073867 for ; Mon, 10 May 2010 06: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 o4A9ZDsT063955 for pgsql-sql@postgresql.org; Mon, 10 May 2010 06:35:13 -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: Mon, 10 May 2010 11:35:14 +0200 Organization: A noiseless patient Spider Lines: 39 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 10 May 2010 09:35:14 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="AnkPUomeHXvuN7UdHvIkog"; logging-data="17841"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lPsxpTgOEgbMm1BEPdDOJ" 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:eh+EF3ALqjPzeaOKwCjRRapjlvM= To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-5 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/42 X-Sequence-Number: 34090 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 after 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