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

2019-09-08 Thread Ali Alizadeh
> 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

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

2019-09-07 Thread Ali Alizadeh
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 gene