public inbox for [email protected]  
help / color / mirror / Atom feed
From: Stephen Frost <[email protected]>
To: Chamath Sajeewa <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: PGSQL returning into in insert statement
Date: Thu, 30 Jul 2020 10:36:00 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CACpofeiBnKyFFf4a3_rFGSkx+_18drQVBv6mMkYQo4W5+oi0JA@mail.gmail.com>
References: <CACpofegcG+Ke2r4yoCpwRKPnV8r+fiGfB1w=ur4M3KHvTFKkpg@mail.gmail.com>
	<[email protected]>
	<CACpofejjgSR_TGVwLb8cBJ=wnuf_g1MH+Aogc3mMNSRwP3C6mg@mail.gmail.com>
	<CACpofeiBnKyFFf4a3_rFGSkx+_18drQVBv6mMkYQo4W5+oi0JA@mail.gmail.com>

Greetings,

* Chamath Sajeewa ([email protected]) wrote:
> Btw oracle support this in plain sql too.

Please don't top-post.

The question here, it would seem, is- where do you expect that
returnvalue to go?  If you want it to be returned to you (making the
INSERT look like a SELECT) then you can just say 'returning value;' and
you don't need to do anything else.

If you want to set a server-side variable with the result, you could do
something like:

=*> with myinsert as
  (insert into test_table(key,value) values ('key1',5) returning value)
  select set_config('myvar.value'::text,myinsert.value::text,true)
  from myinsert;
 set_config 
------------
 5
(1 row)

Which you can then query with:

=*> select current_setting('myvar.value');
 current_setting 
-----------------
 5
(1 row)

Thanks,

Stephen


Attachments:

  [application/pgp-signature] signature.asc (819B, ../[email protected]/2-signature.asc)
  download

view thread (5+ messages)

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: PGSQL returning into in insert statement
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox