我正在
postgresql 9.04中编写一个函数,我试图使用一个将在select语句中使用的变量,然后返回结果.
我提出的这个说法是简单而有效的;但是,所有列都将输出到单个列而不是多个列.
这是我的功能:
create or replace function foo(IN pID integer,OUT project_id integer,OUT project_name text,OUT project_type text,OUT project_description text,OUT project_status text) returns setof record as $$ select project_id,project_name,project_type,project_description,project_status from t_projects where project_id = $1; $$ LANGUAGE sql; select foo(6) -- runs function
当前输出如下所示:
"(6,"test project","inbound","inbound test","processing")"
我如何做到这一点,结果不会并置在一起并分别返回每个列项目?
先谢谢你.
你需要调用这样的函数:
select * from foo(6);
这将返回如下:
project_id | project_name | project_type | project_description | project_status -----------|--------------|--------------|---------------------|---------------- 6 | test project | inbound | inbound test | processing
这是一个postgres的怪癖,它可以称为两种方式,并给你一个结果.您可能想要查看有关设置返回函数的文档,还有其他方法可以执行此操作.哦,这里有一个维基页面,用于编写plpgsql,但大多数应用于sql函数:http://wiki.postgresql.org/wiki/Return_more_than_one_row_of_data_from_PL/pgSQL_functions