pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ali Alizadeh <a.alizadeh@rayanbourse.ir>
To: Adrian Klaver <adrian.klaver@aklaver.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Convert a row to a nested JSON document containing all relations in PostgreSQL
Date: Sun, 8 Sep 2019 12:22:35 +0000
Message-ID: <47223f090e144d8cbd82571e0bdbf6f5@rayanbourse.ir> (raw)
In-Reply-To: <12d11388-7041-841f-c857-a5e5c2c94745@aklaver.com>
References: <7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir>
	<12d11388-7041-841f-c857-a5e5c2c94745@aklaver.com>


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

the children. only one level of depth is fine.

> 2) What procedural language are you using?

PL/pgSQL

As I understand, I need to loop over all columns in the "NEW" record, find out if the column is a foreign key using information_schema or pg_catalog, find the foreign key details like to which column on which table, then perform a dynamic SQL SELECT (because I presume table and column names would be strings, not SQL identifiers) over the target table for the target record, convert the record to JSON and finally assign it to the appropriate key of the JSON object of top-level row. I'm yet trying to write the actual working code for this, for which I welcome any help or directions. And there might be simpler solutions to this problem, which I would like to know about.

Also see my question on SO: https://stackoverflow.com/questions/57830543/convert-a-row-to-a-nested-json-document-containing-all-...




view thread (4+ messages)  latest in thread

Message-ID: <47223f090e144d8cbd82571e0bdbf6f5@rayanbourse.ir>
Permalink:  ../47223f090e144d8cbd82571e0bdbf6f5@rayanbourse.ir/
Also on:    postgresql.org/message-id/47223f090e144d8cbd82571e0bdbf6f5@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, adrian.klaver@aklaver.com
  Subject: Re: Convert a row to a nested JSON document containing all relations in PostgreSQL
  In-Reply-To: <47223f090e144d8cbd82571e0bdbf6f5@rayanbourse.ir>
  References: <7f6e7d7739c04c2cb33681ec8f705541@rayanbourse.ir> <12d11388-7041-841f-c857-a5e5c2c94745@aklaver.com> <47223f090e144d8cbd82571e0bdbf6f5@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