Re: Missing table from in INSERT RETURNING - Mailing list pgsql-general

From John McKown
Subject Re: Missing table from in INSERT RETURNING
Date
Msg-id CAAJSdjgK_BLOsFQspBRXnuCbURu=9Km3aK-=XdS1EFZHaatPEQ@mail.gmail.com
Whole thread Raw
In response to Re: Missing table from in INSERT RETURNING  (David G Johnston <david.g.johnston@gmail.com>)
Responses Re: Missing table from in INSERT RETURNING  (Rémi Cura <remi.cura@gmail.com>)
List pgsql-general
On Tue, Feb 17, 2015 at 2:15 PM, David G Johnston <david.g.johnston@gmail.com> wrote:
On Tue, Feb 17, 2015 at 1:08 PM, John McKown [via PostgreSQL] <[hidden email]> wrote:
I haven't seen any one else reply. I don't know if you've gotten a solution. But the following seemed to work for me:


​mine apparently got bounced...​

 
WITH serie AS (
select s, s*10 as computing
from generate_series(1,10) as s 
)
INSERT INTO test_insert_returning (some_value)
SELECT computing
FROM serie
RETURNING gid, some_value;

​or, "RETURNING some_value / 10"​


From my reading on the RETURNING phrase, you can only return values from the table into which you are doing the INSERT. Not any other table or view which might be referenced.


​This is correct; and I am curious on the use case that requires otherwise.​

​A weird one might be where in data available ("s") in the CTE is in English measure (feet, miles, etc) and the OP wants to insert the equivalent Metric value ("computing") into the table, but needs to return the English value to the caller (why?). He does not want to put the English measure into the table itself, just to be able to return it. And not need to do a reverse conversion. As I said, just a weird thought. From a effervescent fount of weird thoughts - me. Or perhaps what he is storing in the table is a one-way hash of a password, and wants to return the clear-text password to the caller? Hum, that is almost reasonable. I'll need to be more on guard.

 

​David J.​




--
He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown

pgsql-general by date:

Previous
From: David G Johnston
Date:
Subject: Re: Missing table from in INSERT RETURNING
Next
From: Adrian Klaver
Date:
Subject: Re: Issue dumping schema using readonly user