返回select *结果在postgres函数中 [英] Return select * result in postgres function
本文介绍了返回select *结果在postgres函数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在postgres函数内返回查询结果。我尝试了这一点,并使其完美运行:
i am trying to return a query result inside a postgres function. I tried this and worked perfectly:
CREATE OR REPLACE FUNCTION getIncomingAreaMovements(v1 integer)
RETURNS integer AS $$
DECLARE
BEGIN
return id_part_movement From part_movement where id_area_final_destination = $1;
END;
$$ LANGUAGE plpgsql;
事情是我需要一些东西来返回以下结果:
The things is that I need something to return the result of:
Select * From part_movement where id_area_final_destination = $1;
我需要什么回报或应该改变什么才能实现这一目标?
what return do I need or what should I change to achieve this?
推荐答案
这可以通过简单的SQL函数完成:
This can be done with a simple SQL function:
CREATE OR REPLACE FUNCTION get_data(v1 integer)
RETURNS setof part_movement
AS
$$
Select *
From part_movement
where id_area_final_destination = v1;
$$ LANGUAGE sql;
更多详细信息和示例可以在手册中找到:
http://www.postgresql.org/ docs / current / static / xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET
More details and examples can b found in the manual:
http://www.postgresql.org/docs/current/static/xfunc-sql.html#XFUNC-SQL-FUNCTIONS-RETURNING-SET
这篇关于返回select *结果在postgres函数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文