La clause «Retour» peut-elle renvoyer les colonnes source qui ne sont pas insérées?

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

  •  01-11-2019
  •  | 
  •  

Question

Voici un exemple minimal de mon problème réel:

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

Bien sûr, vous pouvez retourner les colonnes insérées avec un returning clause:

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

Vous pouvez également retourner un littéral:

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 |
*/

Mais vous ne pouvez pas retourner les colonnes source:

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
*/

Y a-t-il un moyen d'obtenir w.rnd hors de la finale returning clause?

db <> violon ici

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à dba.stackexchange
scroll top