1N5*_*818 9 postgresql transactions acid go
我找不到一些可以执行以下三项操作的示例:
1)在golang中允许原始sql事务.
2)使用准备好的陈述.
3)回滚查询失败.
我想做这样的事情,但准备好的陈述.
stmt, stmt_err := db.Prepare(`
BEGIN TRANSACTION;
-- Insert record into first table.
INSERT INTO table_1 (
thing_1,
whatever)
VALUES($1,$2);
-- Inert record into second table.
INSERT INTO table_2 (
thing_2,
whatever)
VALUES($3,$4);
END TRANSACTION;
`)
if stmt_err != nil {
return stmt_err
}
res, res_err := stmt.Exec(
thing_1,
whatever,
thing_2,
whatever)
pq: cannot insert multiple commands into a prepared statement
是什么赋予了?是否可以在golang中进行符合ACID的交易?我找不到一个例子.
编辑在这里没有例子.