Combining these three queries in one line in Postgres
I have these Postgres SQL, that is in between some while
loop:
while (.......) {
...
$runStatement = 'update products set abc = "'.data[0].'" where abc = "'.data[1].'";';
...
}
while (.......) {
...
$runStatement = 'update products set xyz = "'.data[0].'" where xyz = "'.dat开发者_如何学JAVAa[1].'";';
...
}
while (.......) {
...
$runStatement = 'update extra_products set abc = "'.data[0].'" where abc = "'.data[1].'";';
...
}
where each loop, data
is actually read from the same array.
Thanks.
Concatenate the statements with semicolons between them and run them in one call to the DB.
You don't need loops. You can do a JOIN in your update, the first table being for instance products, and the second table is a long list of VALUES (old,new),(old,new), etc. This allows to update many rows in one command and is much faster.
精彩评论