Re: Convert a row to a nested JSON document containing all relations in PostgreSQL

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ali Alizadeh <a(dot)alizadeh(at)rayanbourse(dot)ir>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Convert a row to a nested JSON document containing all relations in PostgreSQL
Date: 2019-09-07 19:15:59
Message-ID: 12d11388-7041-841f-c857-a5e5c2c94745@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/6/19 9:35 PM, Ali Alizadeh wrote:
> Hello.
>
>
> In PostgreSQL 10.10, I have created a trigger function that converts the
> `|NEW|` row to a JSON object using |`to_jsonb(NEW)|`. But now I need to
> include the records on the other side of the foreign keys in |`NEW|`
> record in the JSON object in a nested fashion.

Questions:

1) What side are you talking about, the parent of the record or the
children?

2) What procedural language are you using?

>
>
> What is the best and most generic way to accomplish this without prior
> knowledge about the schema of the `|NEW`| record? I need to keep this
> trigger function as generic as possible, because I plan to use it on all
> tables. One level of depth in following foreign keys is currently enough
> for me.
>
>
> Thank you.
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Howard Wells 2019-09-07 22:17:51 How to access Postgres .pgpass file from php?
Previous Message Adrian Klaver 2019-09-07 18:05:16 Re: kind of a bag of attributes in a DB . . .