pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ali Alizadeh <a.alizadeh@rayanbourse.ir>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Convert a row to a nested JSON document containing all relations in PostgreSQL
Date: Sat, 7 Sep 2019 04:35:52 +0000
Message-ID: <7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir> (raw)

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.


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.

view thread (4+ messages)  latest in thread

Message-ID: <7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir>
Permalink:  ../7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir/
Also on:    postgresql.org/message-id/7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir

 · 

reply

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: a.alizadeh@rayanbourse.ir
  Subject: Re: Convert a row to a nested JSON document containing all relations in PostgreSQL
  In-Reply-To: <7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir>
  References: <7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir>

* 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