[英]Postgresql: Return Temp Table From a Stored Procedure
I want to return the result of a query stored in a temp table from a stored procedure. 我想从存储过程返回存储在临时表中的查询结果。 I'm not sure what should be the last statement.
我不确定最后的声明应该是什么。 Any help is appriciated:
任何帮助都适用:
CREATE OR REPLACE FUNCTION public.get_generic_info(
IN in_app_id character varying,
IN key_id uuid)
RETURNS TABLE(info text, last_update timestamp with time zone) AS
$BODY$
BEGIN
CREATE TEMP TABLE result AS
SELECT generic_info.info::text, generic_info.last_update FROM
generic_info
WHERE generic_info.app_id = in_app_id AND generic_info.id = key_id;
-- some data manipulations based on 'result' rows
RETURN ???????;
END;
Your last statement would be like this 您的最后一句话是这样的
RETURN QUERY
SELECT result.info::text, result.last_update FROM
result;
If you are not using TEMP table for anything else, there is no need to create a temp table at all..You can directly do 如果您没有将TEMP表用于其他任何用途,则根本不需要创建临时表。.您可以直接执行
RETURN QUERY
SELECT generic_info.info::text, generic_info.last_update FROM
generic_info
WHERE generic_info.app_id = in_app_id AND generic_info.id = key_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.