Thursday 18 May 2017

Rigth way for this CTE in Postgresql

I can't figure out how to write in the right way this CTE in Postgres via pg in nodejs. I'm little bit confused.

var query = client.query('WITH retid AS (INSERT INTO "Soggetto" (nome, cognome, "regSociale", "partIVA") VALUES ($1, $2, $3, $4) RETURNING id ), INSERT INTO "Tipologia" (privato, azienda) VALUES ($5, $6) SELECT id FROM retid, INSERT INTO "Tipologia2" (cliente, fornitore) VALUES ($7, $8) SELECT id FROM retid ',
                      [sog.nome, sog.cognome, sog.ragioneSociale, sog.partitaIva, sog.cliente, sog.fornitore, sog.privato, sog.azienda], function(err, result){
                        if(err){
                          console.log(err);
                        }else{
                          res.writeHead(200, {'content-type': 'text/plain'});
                          res.end('Insert ok');
                        }
                      });



via user243062

No comments:

Post a Comment