postgresql 中未执行的删除语句
Delete statement not executed in postgresql
我正在创建一个交易,我想在一个 table 中更新一个用户并在另一个中删除属于该用户的一些数据。但是只执行第一个查询,不执行第二个查询。在第二个查询的删除语句中 code
是以逗号分隔的 std::string.
pqxx::connection c(connectionString);
try {
pqxx::work w(c);
pqxx::result r;
c.prepare("user", "update user set started = null, finished = null, task = where id = ");
r = w.prepared("user")(task)(email).exec();
c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code in () and id = )");
r = w.prepared("belongings")(code)(id).exec();
w.commit();
}
我阅读了 SO-thread,它解释了如何 运行 在 commit() 之前进行多个查询。所以我一定是在第二个删除语句中犯了一个错误,但找不到原因。
code
参数被解释为单个文字。您可以尝试使用 any(array expression),
的替代语法,例如:
code = "{abc,def}"; // instead of code = "'abc','def'"
...
c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code = any () and id = )");
r = w.prepared("belongings")(code)(id).exec();
我正在创建一个交易,我想在一个 table 中更新一个用户并在另一个中删除属于该用户的一些数据。但是只执行第一个查询,不执行第二个查询。在第二个查询的删除语句中 code
是以逗号分隔的 std::string.
pqxx::connection c(connectionString);
try {
pqxx::work w(c);
pqxx::result r;
c.prepare("user", "update user set started = null, finished = null, task = where id = ");
r = w.prepared("user")(task)(email).exec();
c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code in () and id = )");
r = w.prepared("belongings")(code)(id).exec();
w.commit();
}
我阅读了
code
参数被解释为单个文字。您可以尝试使用 any(array expression),
的替代语法,例如:
code = "{abc,def}"; // instead of code = "'abc','def'"
...
c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code = any () and id = )");
r = w.prepared("belongings")(code)(id).exec();