From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Ron Clarke <rclarkeai(at)gmail(dot)com> |
Cc: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Postgresql - Json syntax in INSERT RETURNING clause with INTO |
Date: | 2021-05-28 19:41:32 |
Message-ID: | CAKFQuwa8W-LAQJb4MM7Fd8qkUmdSAgz4hVcdjj5S5zD7yRWg0g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Fri, May 28, 2021 at 11:33 AM Ron Clarke <rclarkeai(at)gmail(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Yambu | 2021-05-31 14:37:57 | Check ref cursor |
Previous Message | Vijaykumar Jain | 2021-05-28 19:36:44 | Re: Postgresql - Json syntax in INSERT RETURNING clause with INTO |