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

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

概述我正在 postgresql 9.04中编写一个函数,我试图使用一个将在select语句中使用的变量,然后返回结果. 我提出的这个说法是简单而有效的;但是,所有列都将输出到单个列而不是多个列. 这是我的功能: create or replace function foo(IN pID integer, OUT project_id integer, OUT project_name text 我正在 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_projectswhere project_ID = ;$$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

总结

以上是内存溢出为你收集整理的postgresql – 函数将多个列作为单个列而不是多个列返回全部内容,希望文章能够帮你解决postgresql – 函数将多个列作为单个列而不是多个列返回所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/sjk/1169732.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存