gpt4 book ai didi

postgresql - postgresql 中未执行的删除语句

转载 作者:行者123 更新时间:2023-11-29 12:17:08 25 4
gpt4 key购买 nike

我正在创建一个事务,我想更新一个表中的用户并删除另一个表中属于该用户的一些数据。但是只执行第一个查询,不执行第二个查询。在第二个查询的删除语句中,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 = $1 where id = $2");
r = w.prepared("user")(task)(email).exec();

c.prepare("belongings", "delete from belongings where id in " \
"(select id from info where code in ($1) and id = $2)");
r = w.prepared("belongings")(code)(id).exec();

w.commit();
}

我读了this解释如何在 commit() 之前运行多个查询的 SO 线程。所以我一定是在第二个删除语句中犯了一个错误,但找不到原因。

最佳答案

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 ($1) and id = $2)");
r = w.prepared("belongings")(code)(id).exec();

关于postgresql - postgresql 中未执行的删除语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47348116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com