我在 DBMS (Postgresql) 中有这个存储过程
CREATE OR REPLACE FUNCTION getallentree()
RETURNS SETOF entree AS
$BODY$
begin
select * from entree ;
end;
$BODY$
LANGUAGE plpgsql
调用此过程后:
select * from getAllEntree();
我收到此错误:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function getallentree() line 3 at SQL statement
********** Error **********
ERROR: query has no destination for result data
SQL state: 42601
Hint: If you want to discard the results of a SELECT, use PERFORM instead.
Context: PL/pgSQL function getallentree() line 3 at SQL statement
最佳答案
对于这样简单的查询,最好使用 SQL 函数。与 PL/pgSQL 函数相比,查询优化器可以内联它们并对其进行更好的优化:
CREATE OR REPLACE FUNCTION getallentree()
RETURNS SETOF entree AS
$BODY$
select * from entree ;
$BODY$
LANGUAGE sql;
如果您确实需要 PL/pgSQL 进行其他一些您没有向我们展示的处理,那么 Mureinik 关于使用返回查询
的回答就是正确的选择。
关于java - Postgresql 从表中返回 SETOF 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27958526/