加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 16:28:08 所属栏目:百科 来源:网络整理
导读:我正在 postgresql 9.04中编写一个函数,我试图使用一个将在select语句中使用的变量,然后返回结果. 我提出的这个说法是简单而有效的;但是,所有列都将输出到单个列而不是多个列. 这是我的功能: create or replace function foo(IN pID integer,OUT project_id
我正在 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读