pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Terence Kearns <terencek@isd.canberra.edu.au>
To: pgsql-sql@postgresql.org
Subject: (trigger function) -> ERROR: NEW used in non-rule query
Date: Fri, 18 Jul 2003 18:22:16 +1000
Message-ID: <3F17AE38.5020302@cts.canberra.edu.au> (raw)

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




view thread (7+ messages)  latest in thread

Message-ID: <3F17AE38.5020302@cts.canberra.edu.au>
Permalink:  ../3F17AE38.5020302@cts.canberra.edu.au/
Also on:    postgresql.org/message-id/3F17AE38.5020302@cts.canberra.edu.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: terencek@isd.canberra.edu.au
  Subject: Re: (trigger function) -> ERROR: NEW used in non-rule query
  In-Reply-To: <3F17AE38.5020302@cts.canberra.edu.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox