postgresql – 函数将多个列作为单个列而不是多个列返回

我正在 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

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...