在PostgreSql中,如何在函数或存储过程中同时返回表和输出参数?
我正在尝试从MS Sql Server迁移到PostgreSql。如果创建函数,则不能使用在PostgreSql中,如何在函数或存储过程中同时返回表和输出参数?,postgresql,function,stored-procedures,datatables,return,Postgresql,Function,Stored Procedures,Datatables,Return,我正在尝试从MS Sql Server迁移到PostgreSql。如果创建函数,则不能使用out和inout参数。若创建存储过程,则无法返回表。我不知道怎么做 总之,我想返回表并一起使用以inout参数 就像: CREATE or REPLACE FUNCTION public."test" (INOUT "x" integer, INOUT "y" text) RETURNS TABLE ( "id" integer, "filesize" character varying(36) )
out
和inout
参数。若创建存储过程,则无法返回表。我不知道怎么做
总之,我想返回表并一起使用以inout
参数
就像:
CREATE or REPLACE FUNCTION public."test" (INOUT "x" integer, INOUT "y" text)
RETURNS TABLE (
"id" integer,
"filesize" character varying(36)
)
AS $$
BEGIN
RETURN QUERY
SELECT * FROM public."tbl_employees" ;
END;
$$ LANGUAGE plpgsql;
它可以是存储过程,我不知道怎么做。很简单:你不能这么做。根据:
OUT
和INOUT
参数不能与返回表
注释一起使用。您有什么建议吗?在这种情况下,为什么需要返回x和y?在不了解细节的情况下,很难提出替代方案。您可以执行类似于INOUT x integer、INOUT y text、INOUT refcursor
的操作,然后返回一个从表中选择的游标,但这非常难看。我将输出参数和表调到另一个位置。