pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Miles Elam <miles.elam@productops.com>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: RETURNING to_jsonb(...)
Date: Tue, 5 May 2020 13:25:30 -0700
Message-ID: <7a2ec151-954a-e949-65a1-331732547baf@aklaver.com> (raw)
In-Reply-To: <CAALojA_MaDC5TnjiaF8hPZ6vmXjuRVEpRc7zPOXPx8jfyWp0Dw@mail.gmail.com>
References: <CAALojA_MaDC5TnjiaF8hPZ6vmXjuRVEpRc7zPOXPx8jfyWp0Dw@mail.gmail.com>

On 5/5/20 1:11 PM, Miles Elam wrote:
> How can the new record returned from RETURNING to converted to jsonb?
> 
> For example something like:
> 
>     INSERT INTO my_table (a, b, c) VALUES ('a', 'b', 'c')
>     RETURNING to_jsonb(*);
> 
> 
> or
> 
>     UPDATE my_table SET a = 'a'
>     RETURNING to_jsonb(*);
> 
> 
> or
> 
>     INSERT INTO my_table (a, b, c) VALUES ('a', 'b', 'c')
> 
>     ON CONFLICT DO UPDATE SET a = EXCLUDED.a
> 
>     RETURNING to_jsonb(*);
> 
> 


insert into sample_tbl values(3, 2) returning to_jsonb(sample_tbl.*);
              to_jsonb
-----------------------------------
  {"sample_id": 3, "freezer_fk": 2}
(1 row)

> 
> Thanks in advance


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (2+ messages)

Message-ID: <7a2ec151-954a-e949-65a1-331732547baf@aklaver.com>
Permalink:  ../7a2ec151-954a-e949-65a1-331732547baf@aklaver.com/
Also on:    postgresql.org/message-id/7a2ec151-954a-e949-65a1-331732547baf@aklaver.com

 · 

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: adrian.klaver@aklaver.com, miles.elam@productops.com
  Subject: Re: RETURNING to_jsonb(...)
  In-Reply-To: <7a2ec151-954a-e949-65a1-331732547baf@aklaver.com>
  References: <CAALojA_MaDC5TnjiaF8hPZ6vmXjuRVEpRc7zPOXPx8jfyWp0Dw@mail.gmail.com> <7a2ec151-954a-e949-65a1-331732547baf@aklaver.com>

* 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