问题
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