Re: Getting data from a record variable dynamically

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: Getting data from a record variable dynamically
Дата
Msg-id 3ABEE3C9-E57F-4D52-BB4C-0CD9D9838235@gmail.com
обсуждение исходный текст
Ответ на Getting data from a record variable dynamically  ("Rhys A.D. Stewart" <rhys.stewart@gmail.com>)
Список pgsql-general

> On 5 Jul 2022, at 1:02, Rhys A.D. Stewart <rhys.stewart@gmail.com> wrote:
>
> Greetings All,
>
> I have a trigger that is attached to several different tables. In the
> trigger function I retrieve a single row and I want the info from a
> specific column. This column is dependent on the table in question.
> and I have the column name stored in a variable as well. Without
> writing a conditional for each table, what is the best way to
> dynamically get the data from the record variable?

I would create a simple trigger function for each of those tables that just extracts the value(s) from the field(s) you
mentioned,and then pass those values on to a generic function that does the actual table-independent work. 

The usual trigger pseudo-columns and variables wouldn’t be available in that generic function, but considering that
yourtriggers fire from different tables, you could either pass them on or they (probably) don’t make sense in the
contextof the generic function. 

Alban Hertroys
--
There is always an exception to always.







В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Getting data from a record variable dynamically
Следующее
От: Matthias Apitz
Дата:
Сообщение: lifetime of the old CTID