Tuesday, 15 March 2011

postgresql - How to return multiple rows from PL/pgSQL function? -


I have spent a good time trying to understand it and I am not able to solve it. So, I need your help.

I am trying to write a PL / PGSQL function which gives multiple rows. The function I wrote is shown below but it is not working.

  Fill out or fill the function get_object_fields () returns SETOF REX $$ DECLARE result_record keyMetrics; Returns QUERY SELECT department_id from result_record.visits fact_department_daily where report_date = '2013-06-07'; - Result Results_record; END $ $ LANGUAGE plpgsql; SELECT * FROM get_object_fields;   

This is returning the error:

Error: The function function can not have a parameter in the returning set; I see more bugs:

I see more bugs: < P> First, a SET Returning Functions call has the following syntax

 SELECT * FROM get_object_fields ()  

Second - Returns QUERY Forward results directly to the query output. Can not be stored in the variable - it is no longer possible in postgresql

 is returned QUERY selection ....; - Results for direct return production  

Third - It is better to implement these simple tasks in SQL languages ​​

 or get_object_fields (functions) Returns as $$ SELECT department_id as STOF record ... $$ LANGUAGE sql STABLE;   

No comments:

Post a Comment