From: Alban Hertroys <haramrae@gmail.com>
To: Rhys A.D. Stewart <rhys.stewart@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Getting data from a record variable dynamically
Date: Tue, 5 Jul 2022 09:01:57 +0200
Message-ID: <3ABEE3C9-E57F-4D52-BB4C-0CD9D9838235@gmail.com> (raw)
In-Reply-To: <CACg0vTnDD1G3GgduCAxuU-41VezxPPKowTOGhkFbrJsXXuGdgw@mail.gmail.com>
References: <CACg0vTnDD1G3GgduCAxuU-41VezxPPKowTOGhkFbrJsXXuGdgw@mail.gmail.com>
> 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 your triggers fire from different tables, you could either pass them on or they (probably) don’t make sense in the context of the generic function.
Alban Hertroys
--
There is always an exception to always.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: haramrae@gmail.com, rhys.stewart@gmail.com
Subject: Re: Getting data from a record variable dynamically
In-Reply-To: <3ABEE3C9-E57F-4D52-BB4C-0CD9D9838235@gmail.com>
References: <CACg0vTnDD1G3GgduCAxuU-41VezxPPKowTOGhkFbrJsXXuGdgw@mail.gmail.com> <3ABEE3C9-E57F-4D52-BB4C-0CD9D9838235@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox