hasura-查询没有结果数据的目的地

发布于 2025-02-10 14:30:28 字数 408 浏览 2 评论 0原文

在Hasura中,我正在尝试编写基于PLPGSQL的功能,该功能应返回t_documents。该函数应基于应运行适当的SQL的参数值接受各种可选参数(使用条件检查)并返回记录。这是我的目标。

我从没有参数的简单函数开始,在Hasura中成功创建和跟踪的功能,但是当尝试查询时,它会投掷“查询没有结果数据的目的地”

任何帮助实现目标的帮助是高度赞赏

CREATE OR REPLACE FUNCTION dms.fngetdocs()
 RETURNS SETOF dms.t_documents
 LANGUAGE plpgsql
 STABLE
AS $function$
BEGIN
SELECT *
    FROM dms.t_documents;
END;    
$function$

In Hasura, I'm trying write a plpgsql based function which should return the t_documents. The function should accept various optional arguments, based on the argument values it should run appropriate SQL (using IF conditional checks) and return the records. This is my goal.

I've started with simple function with no arguments, the function created and tracked successfully in Hasura, however when try to query it throws "query has no destination for result data"

Any help to achieve the goal is highly appreciated

CREATE OR REPLACE FUNCTION dms.fngetdocs()
 RETURNS SETOF dms.t_documents
 LANGUAGE plpgsql
 STABLE
AS $function$
BEGIN
SELECT *
    FROM dms.t_documents;
END;    
$function$

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2025-02-17 14:30:28

每个sql语句返回行(例如选择,但in带有返回等)必须有一个目标数据的目标。这就是错误消息告诉您的。分配变量或返回到呼叫者。对于丢弃结果,请使用perrive而不是选择。请参阅:

//stackoverflow.com/questions/10115806/select-erect-or-perform-in-a-pl-pgsql-function/10117015#10117015"> select 行。您的PL/PGSQL函数将像这样工作:

CREATE OR REPLACE FUNCTION dms.fngetdocs()
  RETURNS SETOF dms.t_documents
  LANGUAGE plpgsql STABLE PARALLEL SAFE AS
$func$
BEGIN
   RETURN QUERY
   SELECT * FROM dms.t_documents;
END
$func$

请参阅:

当然几乎没有任何意义。而不是调用该函数,而是直接使用select *从dms.t_documents;直接使用。

或使用更简单的SQL函数,其中选择的结果自动返回:

CREATE OR REPLACE FUNCTION dms.fngetdocs()
  RETURNS SETOF dms.t_documents
  LANGUAGE sql STABLE PARALLEL SAFE AS
$func$
SELECT * FROM dms.t_documents;
$func$;

请参阅有关添加并行安全的手册。

Every SQL statement returning rows (like SELECT, but also INSERT with RETURNING etc.) must have a target for the resulting data. That's what the error message tells you. Either assign variables or return to the caller. To discard results instead, use PERFORM instead of SELECT. See:

But you obviously want to return rows. Your PL/pgSQL function would work like this:

CREATE OR REPLACE FUNCTION dms.fngetdocs()
  RETURNS SETOF dms.t_documents
  LANGUAGE plpgsql STABLE PARALLEL SAFE AS
$func$
BEGIN
   RETURN QUERY
   SELECT * FROM dms.t_documents;
END
$func$

See:

Makes very little sense, of course. Instead of calling that function you would just use SELECT * FROM dms.t_documents; directly.

Or use a simpler SQL function, where the result of a SELECT is returned automatically:

CREATE OR REPLACE FUNCTION dms.fngetdocs()
  RETURNS SETOF dms.t_documents
  LANGUAGE sql STABLE PARALLEL SAFE AS
$func$
SELECT * FROM dms.t_documents;
$func$;

See the manual about the added PARALLEL SAFE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文