From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | "Rhys A(dot)D(dot) Stewart" <rhys(dot)stewart(at)gmail(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Dynamically accessing columns from a row type in a trigger |
Date: | 2023-08-13 04:53:56 |
Message-ID: | CACJufxHVWB+0-qZOwryOZ4Usx2N5u68JMKxsqjCfzK-3ud=FCg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, Aug 13, 2023 at 11:27 AM Rhys A.D. Stewart
<rhys(dot)stewart(at)gmail(dot)com> 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.
>
> 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:
>
> `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.
>
google lead me to this post:
https://stackoverflow.com/questions/55245353/access-dynamic-column-name-of-row-type-in-trigger-function
> table, or maybe look into using TG_ARGS.
maybe you are referring to TG_ARGV.
example of TG_ARGV =>
https://git.postgresql.org/cgit/postgresql.git/tree/src/test/regress/expected/triggers.out
From | Date | Subject | |
---|---|---|---|
Next Message | Marc Millas | 2023-08-13 23:14:38 | Re: pb with big volumes |
Previous Message | David G. Johnston | 2023-08-13 04:34:59 | Re: Dynamically accessing columns from a row type in a trigger |