我正在使用pg-promise
node.js,我想确保我正确理解有关交易的文档。
假设我执行了以下交易:
db.tx(function(t) {
t.any('SELECT * FROM users')
.then(function(users) {
var queries = [];
for (var i =0; i < users.length; i++) {
queries.push(t.any("INSERT INTO stocks_owned (ticker, shares, user_id) VALUES ('GOOG', 10, $1)", users[i].user_id));
}
return t.batch(queries);
})
})
这最终会执行哪些 postgres 查询?
postgres 交易将是:
BEGIN;
SELECT * FROM users;
SAVEPOINT my_savepoint;
INSERT INTO stocks_owned (ticker, shares, user_id) VALUES ('GOOG', 10, 1);
INSERT INTO stocks_owned (ticker, shares, user_id) VALUES ('GOOG', 10, 2);
...
INSERT INTO stocks_owned (ticker, shares, user_id) VALUES ('GOOG', 10, 999);
COMMIT;
换句话说,包含在其他查询中的子查询是否包含在同一个BEGIN/COMMIT
块中?