How can I get one OLD.* field in a dynamic query inside a trigger function ?

From: Bruno Baguette <bruno(dot)baguette(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How can I get one OLD.* field in a dynamic query inside a trigger function ?
Date: 2009-10-24 03:58:37
Message-ID: 4AE27B6D.70404@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello !

I'm trying to write a little trigger function with variable arguments
quantity (at least one, but can be 2,3,4 arguments).
Theses arguments are fields name, so only varchar variable.

Since it is a dynamic query, I use the EXECUTE statement as explained on
<http://www.postgresql.org/docs/8.3/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN>

CREATE OR REPLACE FUNCTION delete_acl_trigger() RETURNS trigger AS
$delete_acl_trigger$
DECLARE
BEGIN
FOR i IN 0 .. TG_NARGS LOOP
EXECUTE 'SELECT delete_acl(OLD.' || TG_ARGV[i] || ');';
END LOOP;
RETURN OLD;
END;
$delete_acl_trigger$ LANGUAGE plpgsql;

But, when the trigger is triggered, I receive this error message :
"Query failed: ERROR: OLD used in query that is not in a rule"

How can I get the value of the OLD.' || TG_ARGV[i] field ?

Many thanks in advance !

Kind regards,

--
Bruno Baguette - bruno(dot)baguette(at)gmail(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2009-10-24 04:46:47 Re: How can I get one OLD.* field in a dynamic query inside a trigger function ?
Previous Message semi-ambivalent 2009-10-24 03:32:06 Re: auto-filling a field on insert