A trigger that acts on a column with a given column name - Mailing list pgsql-general

From BigSmoke
Subject A trigger that acts on a column with a given column name
Date
Msg-id b9b59ba0050707122873540efd@mail.gmail.com
Whole thread Raw
Responses Re: A trigger that acts on a column with a given column name
Re: A trigger that acts on a column with a given column
List pgsql-general
In a trigger function, I'm trying to refer to a column given by an argument
to the trigger function.

The trigger function fires on deletes and is responsible for deleting messages
that are referred to using foreign keys which are named differently in different
tables (thus the foreign key's column name as an argument).

Thus, in my trigger function, I need something like this:

DECLARE
  message_id INTEGER;
BEGIN
  message_id := quote_literal('OLD.' || TG_ARGV[0]);

This, of course, doesn't get me the value of the column named TG_ARGV[0] in
OLD, but instead just gives me an error because I'm trying to assign the
string value returned by quote_literal() to an integer.

So, my question is: how can I convince PostgreSQL that a string which I've
constructed is in fact the name of a column? I've tries some variation with
SELECT INTO, but I keep bumping into the same question ...

Any help much so appreciated.

 - Rowan

--
Morality is usually taught by the immoral.

pgsql-general by date:

Previous
From: Ying Lu
Date:
Subject: find objects under a specific tablespace
Next
From: Michael Fuhr
Date:
Subject: Re: table name as variable within Function