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

From David G. Johnston
Subject Re: Getting data from a record variable dynamically
Date
Msg-id CAKFQuwb73M1ULc+ZFcrEDQiTYN9diZyMZMfsc5WrWhQTXzcifA@mail.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 Mon, Jul 4, 2022 at 4:03 PM Rhys A.D. Stewart <rhys.stewart@gmail.com> wrote:

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.

The only workaround I can think of is to wrap the query that populates
the record variable in a to_jsonb function and then subscript that.


Is there a better way?


Not in the strongly typed language that is SQL; you will be unable to use first-tier types in that way.  You indeed need to create a type that itself is dynamic in terms of the information it stores (jsonb works) which also involves throwing away the static typing of the outer layer and devolving everything to basically text.

David J.

pgsql-general by date:

Previous
From: "Rhys A.D. Stewart"
Date:
Subject: Getting data from a record variable dynamically
Next
From: Alban Hertroys
Date:
Subject: Re: Getting data from a record variable dynamically