如何从PostgreSQL 9.0函数(“存储过程”)获取数据集

问题描述:

我正在尝试从PostgreSQL 9.0函数获取数据集,我无法使用存储过程。

I'm trying to obtain a data set from a PostgreSQL 9.0 function and I'm not able to with stored procedures.

我是Postgres的新用户周,所以让我解释一下我的条款:

I'm new to Postgres this week so let me explain my terms:

在pgAdmin III中,我可以输入命令:

In pgAdmin III I can enter the command:

SELECT * FROM member;

并收到以下数据输出:

memberid   membername
1          Bill Smith
2          Joe Smith

我尝试创建多个功能(表/ SETOF / etc),非常像:

I tried creating MANY functions (tables / SETOF / etc) pretty much like:

CREATE OR REPLACE FUNCTION get_all_members()
RETURNS SET OF member AS
'select * from member;'

当我在pgAdmin中运行它们(或从程序中调用它们)时,我得到以下内容:

When I run them in pgAdmin (or call them from a program) I get the following:

SELECT get_all_members()

结果:

get_all_members
member
(1, "Bill Smith")
(2, "Joe Smith")

有没有可以从FUNCTION(存储过程)将其作为数据集,可以直接输入SQL命令。

Is there anyway to get this as a data set from a FUNCTION (Stored Procedure) as I can with directly entering SQL commands.

你的帮助是非常感激的!!!

You help is GREATLY appreciated!!!

你可以得到通过修改你的选择语句,这样看起来像这样:

You can get the per column output by modifying your select statement a bit so it looks like so:

SELECT * FROM get_all_members()

这将像列表一样输出列,就像正常查询一样。

This will give you the column by column output just like doing the query normally.

请参阅设置返回功能文件。