如何从 pqxx 调用重载的远程过程?
程序例如:
CREATE OR REPLACE FUNCTION foo(str text) RETURNS text AS $$
BEGIN
RETURN 'text';
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION foo(num integer) RETURNS text AS $$
BEGIN
RETURN 'int';
END;
$$ LANGUAGE plpgsql;
C++ 代码:
pqxx::connection connection(/* credentials */);
std::string query_mark = "test_procedure_mark";
connection.prepare(query_mark, "SELECT foo($1);");
//first case
pqxx::work work(connection);
pqxx::result res = work.prepared(query_mark)("text").exec();
work.commit();
std::string ans = res[0][0].as(std::string("")); //ans here "text"
//second case
pqxx::work work(connection);
pqxx::result res = work.prepared(query_mark)(1).exec();
work.commit();
std::string ans = res[0][0].as(std::string("")); //ans here "text"
如何从 C++ 代码中调用“foo(num integer)”?例如,“ans”中的所需结果“int”。
psql.exe 输出:
选择 foo(1); 返回“int”
选择 foo("测试"); 返回“文本”
提前致谢。