La clausola "ritorno" può essere inserita colonne di sorgente di ritorno che non sono inserite?

dba.stackexchange https://dba.stackexchange.com/questions/50693

  •  01-11-2019
  •  | 
  •  

Domanda

Ecco un esempio minimo del mio problema del mondo reale:

create table t(id serial primary key, rnd double precision);

Naturalmente puoi restituire le colonne inserite con a returning clausola:

with w as (insert into t(rnd) values(random()) returning *)
insert into t(rnd) select random() from w returning *;
/*
| ID |            RND |
|----|----------------|
|  9 | 0.203221440315 |
*/

Puoi anche restituire un letterale:

with w as (insert into t(rnd) values(random()) returning *)
insert into t(rnd) select random() from w returning *, 1.0 dummy;
/*
| ID |            RND | DUMMY |
|----|----------------|-------|
| 11 | 0.594980469905 |     1 |
*/

Ma non puoi restituire le colonne di origine:

with w as (insert into t(rnd) values(random()) returning *)
insert into t(rnd) select random() from w returning *, w.rnd;
/*
ERROR: missing FROM-clause entry for table "w": with w as (insert into t(rnd) values(random()) returning *) insert into t(rnd) select random() from w returning *, w.rnd
*/

C'è un modo per ottenere w.rnd fuori dal finale returning clausola?

db <> violino qui

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top