Re: Getting data from a record variable dynamically

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Getting data from a record variable dynamically
Дата
Msg-id CAKFQuwb73M1ULc+ZFcrEDQiTYN9diZyMZMfsc5WrWhQTXzcifA@mail.gmail.com
обсуждение исходный текст
Ответ на Getting data from a record variable dynamically  ("Rhys A.D. Stewart" <rhys.stewart@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: "Rhys A.D. Stewart"
Дата:
Сообщение: Getting data from a record variable dynamically
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: Getting data from a record variable dynamically