gpt4 book ai didi

c++ - SOCI 无法准备声明

转载 作者:行者123 更新时间:2023-11-28 06:44:35 26 4
gpt4 key购买 nike

我有这样一个函数:

CREATE OR REPLACE FUNCTION get_path_set_1(IN pathset_id_in character varying, OUT id character varying, OUT pathset_id character varying, OUT utility double precision)
RETURNS SETOF record AS
$BODY$

begin
if exists(SELECT 1 FROM "PathSet_Scaled_HITS_distinctODs" WHERE "ID" = $1) then
return query SELECT "ID", "PATHSET_ID", "UTILITY"
FROM "SinglePath_Scaled_HITS_distinctODs"
where "PATHSET_ID" = $1;
end if;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION get_path_set_1(character varying)
OWNER TO postgres;

当我在我的程序中调用它时:

std::string testStr("43046,75502");// or std::string testStr("'43046,75502'");
soci::rowset<sim_mob::SinglePath> rs = (sql.prepare << "get_path_set_1(:pathset_id_in)",soci::use(testStr));

我得到以下异常:

terminate called after throwing an instance of 'soci::postgresql_soci_error'
what(): Cannot prepare statement. ERROR: syntax error at or near "get_path_set_1"
LINE 1: get_path_set_1($1)

如果你帮我检测丢失的部分,我将不胜感激谢谢

最佳答案

不会解决您报告的错误。但是简化你的功能:

CREATE OR REPLACE FUNCTION get_path_set_1(pathset_id_in varchar)
RETURNS TABLE(id varchar, pathset_id varchar, utility double precision) AS
$func$
BEGIN
RETURN QUERY
SELECT "ID", "PATHSET_ID", "UTILITY"
FROM "SinglePath_Scaled_HITS_distinctODs"
WHERE "PATHSET_ID" = $1;
END
$func$ LANGUAGE plpgsql;
  • RETURNS TABLE是现代的、更优雅的、等效的组合形式 RETURNS SETOF recordOUT参数。

  • IF exists ...在这里不给你买任何东西。运行查询;如果未找到任何内容,则不返回任何内容。用一半的成本获得相同的结果。

关于c++ - SOCI 无法准备声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25239233/

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