A trigger that acts on a column with a given column name

Поиск
Список
Период
Сортировка
От BigSmoke
Тема A trigger that acts on a column with a given column name
Дата
Msg-id b9b59ba0050707122873540efd@mail.gmail.com
обсуждение исходный текст
Ответы Re: A trigger that acts on a column with a given column name  (Michael Fuhr <mike@fuhr.org>)
Re: A trigger that acts on a column with a given column  ("Karl O. Pinc" <kop@meme.com>)
Список 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 по дате отправления:

Предыдущее
От: Ying Lu
Дата:
Сообщение: find objects under a specific tablespace
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: table name as variable within Function