I am trying to add a computed field to my graphql table "user" in schema "abc" using the hasura API but receiving the following error :
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
The function is added correctly :
CREATE OR REPLACE FUNCTION abc.fullname(userrow abc.user)
RETURNS TEXT AS $$
BEGIN
SELECT userrow.first_name || ' ' || userrow.last_name;
END;
$$ LANGUAGE plpgsql;
I am able to select the function "fullname" from the dropdown but getting an error on adding computed field. Any guidance is appreciated. Thank you.
The error message is trying to tell you. You need to explicitly declare the function as immutable
so it can be used in the definition of the computed column:
create or replace function abc.fullname(userrow abc.user)
returns text immutable as $$
begin
select userrow.first_name || ' ' || userrow.last_name;
end;
$$ language plpgsql;