Re: Dynamically accessing columns from a row type in a trigger

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Dynamically accessing columns from a row type in a trigger
Дата
Msg-id 40a49cf0-c1ae-3c96-ad62-35fc44746774@aklaver.com
обсуждение исходный текст
Ответ на Re: Dynamically accessing columns from a row type in a trigger  ("Rhys A.D. Stewart" <rhys.stewart@gmail.com>)
Список pgsql-general
On 8/12/23 20:21, Rhys A.D. Stewart wrote:
> Hey Adrian,
> 
> Thanks for your response. I don't think I explained myself clearly.
> pk_col is not the column name. pk_col is a variable that holds the
> name of a column. This is one trigger for several tables with varying
> structures. So pk_col would be a column specific to the current
> TG_TABLE_NAME when the trigger is invoked. This is why in my example I
> had to use EXECUTE to get the value of the pk_col from OLD.

So you are looking for a generic solution.

>  
> Actually, now that I'm thinking about it, I don't really want to store
> the value into a variable because the pk_col might be of any given
> type. So ideally, I'd love a way to just get the value from OLD and
> use it directly in another query. Something along the lines of:

The issue then is determining what value to get from OLD.

Is that generic e.g always the Primary Key or will it vary?

> 
> `EXECUTE format('SELECT * FROM %1$I.sometable WHERE pk = $1', myschma)
> USING OLD['pk_col']`.
> 
> I reckon I may have to look at just generating a trigger function per
> table, or maybe look into using TG_ARGS.
> 
> 
> Rhys
> Peace & Love | Live Long & Prosper
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




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

Предыдущее
От: "Rhys A.D. Stewart"
Дата:
Сообщение: Re: Dynamically accessing columns from a row type in a trigger
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Dynamically accessing columns from a row type in a trigger