Re: Getting data from a record variable dynamically

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "Rhys A(dot)D(dot) Stewart" <rhys(dot)stewart(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting data from a record variable dynamically
Date: 2022-07-05 01:03:17
Message-ID: CAKFQuwb73M1ULc+ZFcrEDQiTYN9diZyMZMfsc5WrWhQTXzcifA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jul 4, 2022 at 4:03 PM Rhys A.D. Stewart <rhys(dot)stewart(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2022-07-05 07:01:57 Re: Getting data from a record variable dynamically
Previous Message Rhys A.D. Stewart 2022-07-04 23:02:39 Getting data from a record variable dynamically