Tweeted twitter.com/StackDBAs/status/868312018725588992
2 added 37 characters in body
source | link

thisThis query works for me when i triedI tried in PG admin query tool:

UPDATE bankdetails SET bank_details = 'mysore' ,"PAN"= 123,bank_acc = 456,
                       "UAN"=789,tax = 'myy'   
WHERE  user_id = 79;
INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax)
       SELECT 79,'mysore',123,456,789,'myy'
       WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id=79);

later iLater I implemented in my code like this:

db.query('UPDATE bankdetails SET bank_details = $2 ,"PAN"= $3,bank_acc = $4,"UAN"=$5,tax = $6 WHERE user_id = $1; INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax) SELECT $1,$2,$3,$4,$5,$6 WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id = $1);', [companyuser.rows[0]._id, data.bankDetails.bank_details, data.bankDetails.PAN, data.bankDetails.bank_acc, data.bankDetails.UAN, data.bankDetails.tax],function(err,bank) {

                if (err) return callback(new Error('error'));
})

it says "cannot insert multiple commands into a prepared statement" can:

cannot insert multiple commands into a prepared statement

Can some one guide me here?

this query works for me when i tried in PG admin query tool

UPDATE bankdetails SET bank_details = 'mysore' ,"PAN"= 123,bank_acc = 456,"UAN"=789,tax = 'myy'  WHERE user_id = 79;
INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax)
       SELECT 79,'mysore',123,456,789,'myy'
       WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id=79);

later i implemented in my code like this

db.query('UPDATE bankdetails SET bank_details = $2 ,"PAN"= $3,bank_acc = $4,"UAN"=$5,tax = $6 WHERE user_id = $1; INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax) SELECT $1,$2,$3,$4,$5,$6 WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id = $1);', [companyuser.rows[0]._id, data.bankDetails.bank_details, data.bankDetails.PAN, data.bankDetails.bank_acc, data.bankDetails.UAN, data.bankDetails.tax],function(err,bank) {

                if (err) return callback(new Error('error'));
})

it says "cannot insert multiple commands into a prepared statement" can some one guide me here?

This query works for me when I tried in PG admin query tool:

UPDATE bankdetails SET bank_details = 'mysore' ,"PAN"= 123,bank_acc = 456,
                       "UAN"=789,tax = 'myy' 
WHERE  user_id = 79;
INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax)
       SELECT 79,'mysore',123,456,789,'myy'
       WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id=79);

Later I implemented in my code like this:

db.query('UPDATE bankdetails SET bank_details = $2 ,"PAN"= $3,bank_acc = $4,"UAN"=$5,tax = $6 WHERE user_id = $1; INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax) SELECT $1,$2,$3,$4,$5,$6 WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id = $1);', [companyuser.rows[0]._id, data.bankDetails.bank_details, data.bankDetails.PAN, data.bankDetails.bank_acc, data.bankDetails.UAN, data.bankDetails.tax],function(err,bank) {

                if (err) return callback(new Error('error'));
})

it says:

cannot insert multiple commands into a prepared statement

Can some one guide me here?

1
source | link

cannot insert multiple commands into a prepared statement

this query works for me when i tried in PG admin query tool

UPDATE bankdetails SET bank_details = 'mysore' ,"PAN"= 123,bank_acc = 456,"UAN"=789,tax = 'myy'  WHERE user_id = 79;
INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax)
       SELECT 79,'mysore',123,456,789,'myy'
       WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id=79);

later i implemented in my code like this

db.query('UPDATE bankdetails SET bank_details = $2 ,"PAN"= $3,bank_acc = $4,"UAN"=$5,tax = $6 WHERE user_id = $1; INSERT INTO bankdetails (user_id,bank_details,"PAN",bank_acc,"UAN",tax) SELECT $1,$2,$3,$4,$5,$6 WHERE NOT EXISTS (SELECT 1 FROM bankdetails WHERE user_id = $1);', [companyuser.rows[0]._id, data.bankDetails.bank_details, data.bankDetails.PAN, data.bankDetails.bank_acc, data.bankDetails.UAN, data.bankDetails.tax],function(err,bank) {

                if (err) return callback(new Error('error'));
})

it says "cannot insert multiple commands into a prepared statement" can some one guide me here?