How to obtain a data set from PostgreSQL 9.0 Function (“stored procedure”)

回眸只為那壹抹淺笑 提交于 2019-12-22 08:47:22

问题


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

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

In pgAdmin III I can enter the command:

SELECT * FROM member;

And receive the following Data Output:

memberid   membername
1          Bill Smith
2          Joe Smith

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;'

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

SELECT get_all_members()

Results:

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

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!!!


回答1:


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.

See set returning functions in the documentation.



来源:https://stackoverflow.com/questions/13110649/how-to-obtain-a-data-set-from-postgresql-9-0-function-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!