Re: Postgresql - Json syntax in INSERT RETURNING clause with INTO - Mailing list pgsql-sql

From David G. Johnston
Subject Re: Postgresql - Json syntax in INSERT RETURNING clause with INTO
Date
Msg-id CAKFQuwa8W-LAQJb4MM7Fd8qkUmdSAgz4hVcdjj5S5zD7yRWg0g@mail.gmail.com
Whole thread Raw
In response to Postgresql - Json syntax in INSERT RETURNING clause with INTO  (Ron Clarke <rclarkeai@gmail.com>)
List pgsql-sql
On Fri, May 28, 2021 at 11:33 AM Ron Clarke <rclarkeai@gmail.com> wrote:
-- So how do I effectively merge the output of a returning clause into a single json value
-- is this possible ??          

Depends on what you mean by "merge"...but the most simple answer to "how do I turn multiple rows of data into a single row" is usually "by using an aggregate function and a group by clause".  In this case the "json_agg()" and "json_object_agg()" functions meet the basic criteria.

Also, to do anything beyond simply returning the table constructed by the returning clause you need to move the statement into a CTE and do you work on its results.

David J.

pgsql-sql by date:

Previous
From: Vijaykumar Jain
Date:
Subject: Re: Postgresql - Json syntax in INSERT RETURNING clause with INTO
Next
From: Yambu
Date:
Subject: Check ref cursor