Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 3B6932E3EF4 for ; Thu, 7 Feb 2008 03:52:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 89030-04 for ; Thu, 7 Feb 2008 03:52:22 -0400 (AST) Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by postgresql.org (Postfix) with ESMTP id 0CE172E032B for ; Thu, 7 Feb 2008 03:52:25 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay04.plus.net with esmtp (Exim) id 1JN1YX-0001bq-88; Thu, 07 Feb 2008 07:52:25 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 007C1274061; Thu, 7 Feb 2008 07:52:22 +0000 (GMT) Message-ID: <47AAB8B6.70807@archonet.com> Date: Thu, 07 Feb 2008 07:52:22 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Tiziano Slack CC: pgsql-sql@postgresql.org Subject: Re: TG_TABLE_NAME as identifier References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 5c5dacc897c6219e664f8bd8e39e778b X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/53 X-Sequence-Number: 30144 Tiziano Slack wrote: > Thanks for the precious tips, but unfortunately the syntax: > EXECUTE 'INSERT INTO '|| TG_TABLE_NAME ||' SELECT '|| NEW.*;is parsed correctly, but when the trigger is fired the following error is returned > > ERROR: column "*" not found in data type mytable > CONTEXT: SQL statement "SELECT 'INSERT INTO '|| $1 ||' SELECT '|| $2 .*" > > Using > EXECUTE 'INSERT INTO '|| TG_TABLE_NAME ||' SELECT NEW.*'; > instead, returns: > > ERROR: NEW used in query that is not in a rule > CONTEXT: SQL statement "INSERT INTO anag_referenti SELECT NEW.*" > > Hope someone can show me another way to do that, if exists ;) You'll have to build the INSERT in full - column by column. Have you considered plperl / pltcl etc. - that makes it easier to do. -- Richard Huxton Archonet Ltd