Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id C2B609F974E for ; Sat, 11 Aug 2007 05:17:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 31417-03 for ; Sat, 11 Aug 2007 05:17:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.176]) by postgresql.org (Postfix) with ESMTP id 60E549F973D for ; Sat, 11 Aug 2007 05:16:49 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so1280383wah for ; Sat, 11 Aug 2007 01:16:47 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZrqMn72yzxwLjbczHxqTJAV4frA7XowWp1gkxUqJkkTV2jSFVhoGiw+yjlqVIhifSDzN9dioWiGrGSlDG3oigWh2+ofA/yB4S8GmpZFJM7uVWk0cIOetUk0Cf4OOwO1hFmMXf+KPI34q10mHVxATmr/4+Mpbk8BWKE3QaH/cM+U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=MnBAvS9T+FX8VsVfPoEOiCbsdYeS1vYchqNRKtnjQJbx+2T/vVceHUYAWV4yDCNLsMSM/MMKeYdSn/fzQ7JLOc4qhMstCSFusFFF7aRoZOYAGXoS3zel9EhGOS7hxyxNQ7vN8UDK6QCVVT+6XnEPPfGp2mc9vnlRaGGb+emaKEA= Received: by 10.143.14.16 with SMTP id r16mr594763wfi.1186820207132; Sat, 11 Aug 2007 01:16:47 -0700 (PDT) Received: by 10.142.88.4 with HTTP; Sat, 11 Aug 2007 01:16:47 -0700 (PDT) Message-ID: <162867790708110116h6825b5cj7a9f93a97f1328af@mail.gmail.com> Date: Sat, 11 Aug 2007 10:16:47 +0200 From: "Pavel Stehule" To: "Javier Fonseca V." Subject: Re: Trigger Procedure Error: NEW used in query that is not in a rule Cc: pgsql-sql@postgresql.org In-Reply-To: <86d227fd0708110045t16e39442xd35746eb59296362@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <86d227fd0708110043q341a2908q67e87570bca89492@mail.gmail.com> <86d227fd0708110045t16e39442xd35746eb59296362@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/93 X-Sequence-Number: 29031 NEW is only plpgsql variable. It isn't visible on SQL level. You cannot use new.*, you can: execute 'INSERT ...' || 'VALUES(' || new.a || ',' || new.b .... regards Pavel 2007/8/11, Javier Fonseca V. : > > > Hello. > > I'm doing a Trigger Procedure in pl/pgSQL. It makes some kind of auditing. > > I think that it's working alright except for the next line: > > EXECUTE 'INSERT INTO ' || quote_ident(somedynamictablename) > || ' SELECT new.*'; > > PostgreSQL keeps telling me: "ERROR: NEW used in query that is not in a > rule". I think that this NEW problem is because of the scope of the EXECUTE > statement (outside the scope of the trigger), so it doesn't recognize the > NEW record. > > Maybe I could fix it concatenating column names and the 'new' values but I > want to do my trigger as flexible as possible (I have several tables to > audit). > > Somebody has any suggestion? > > Thanks a lot, > > Javier