1

我正在尝试使用 hasura API 在模式“abc”中将计算字段添加到我的 graphql 表“用户”,但收到以下错误:

Saving computed field failed
in table "abc.user": in computed field "full_name": the computed field "full_name" 
cannot be added to table "abc.user" because the function "abc.fullname" is 
of type VOLATILE; cannot be added as a computed field

该功能已正确添加:

    CREATE OR REPLACE FUNCTION abc.fullname(userrow abc.user)
    RETURNS TEXT AS $$
BEGIN
    SELECT userrow.first_name || ' ' || userrow.last_name;
END;
$$ LANGUAGE plpgsql;

我可以从下拉列表中选择函数“全名”,但在添加计算字段时出现错误。任何指导表示赞赏。谢谢你。

在此处输入图像描述

4

1 回答 1

2

错误信息试图告诉你。您需要显式声明该函数,immutable以便可以在计算列的定义中使用它:

create or replace function abc.fullname(userrow abc.user)
returns text immutable as $$
begin
    select userrow.first_name || ' ' || userrow.last_name;
end;
$$ language plpgsql;
于 2020-10-09T21:42:30.573 回答