X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id C90FCCCC08 for ; Fri, 18 Jul 2003 08:22:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 58969-02 for ; Fri, 18 Jul 2003 08:22:53 +0000 (GMT) Received: from isd.canberra.edu.au (isd.canberra.edu.au [137.92.10.5]) by svr1.postgresql.org (Postfix) with ESMTP id 186A8CC9C1 for ; Fri, 18 Jul 2003 05:22:22 -0300 (ADT) Received: from cts.canberra.edu.au (fooey.canberra.edu.au [137.92.10.57]) by isd.canberra.edu.au (8.12.9/8.12.6) with ESMTP id h6I8MqCF008167 for ; Fri, 18 Jul 2003 18:22:52 +1000 (EST) Message-ID: <3F17AE38.5020302@cts.canberra.edu.au> Date: Fri, 18 Jul 2003 18:22:16 +1000 From: Terence Kearns User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3.1) Gecko/20030425 X-Accept-Language: en-au, en-gb, en, en-us MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: (trigger function) -> ERROR: NEW used in non-rule query Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/249 X-Sequence-Number: 14363 I'm writing a trigger which wants to reference the pre-defined NEW record. I can do this idval := NEW.blah; This works fine!!! What I really need to do is idval := NEW.(quote_ident(TG_ARGV[3])); or this idval := NEW.(TG_ARGV[3]); unfortunately this returns "ERROR: NEW used in non-rule query" I've also tried using EXECUTE ''SELECT NEW.'' || quote_ident(TG_ARGV[3]); (to test if I can use a FOR-IN-EXECUTE to extract it) and it produces exactly the same error. Obviously NEW goes out of scope for some reason. I can understand the case with EXECUTE but the other statements should have worked :( This is very frustrating because it is the *ONLY* thing standing in the way of me solving a larger problem (which I will use to repsond to another thread in this forum). Does anyone know how to access an arbitarily specified field of the NEW record in a trigger function. I need this because arguments to a function in the trigger definition cannot be NEW.blah, they have to be static/literals (which is likely to be for the same reason that NEW goes out of scope any time I try to do something dynamic when evaluating a field on it). FYI: ref doco at http://www.postgresql.org/docs/7.3/interactive/plpgsql-trigger.html using pg 7.3.3 -- Terence Kearns ~ ph: +61 2 6201 5516 IT Database/Applications Developer Enterprise Information Systems Client Services Division University of Canberra www.canberra.edu.au