Re: Getting data from a record variable dynamically - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Getting data from a record variable dynamically
Date
Msg-id 3ABEE3C9-E57F-4D52-BB4C-0CD9D9838235@gmail.com
Whole thread Raw
In response to Getting data from a record variable dynamically  ("Rhys A.D. Stewart" <rhys.stewart@gmail.com>)
List 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 by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Getting data from a record variable dynamically
Next
From: Matthias Apitz
Date:
Subject: lifetime of the old CTID