Is there any way to return SETOF without table name in Hasura graphql custom sql function
Asked Answered
O

0

7

I have created custom sql function in hasura and tracked it. But need to write table name in "RETURNS SETOF <table-name>" (Refer: https://docs.hasura.io/1.0/graphql/manual/schema/custom-functions.html). Here I cannot create new table having schema same as the function is returning columns. I have lots of function to create so that I want a solution where I can create a function having return SETOF without table name.

Even in hasura function can't returns virtual table (i.e. RETURNS Table(column1 text, column2 text, column3 text) )

I tried "create type" and use it as

CREATE TYPE temp_type AS
(column1 text, column2 text, column3 text
);

But didn't work and giving following error:

"the function "my_function" cannot be tracked because the function does not return a SETOF table"

Any solution on this?

Here is my function

CREATE  FUNCTION my_function(fromDate text, toDate text)
RETURNS  SETOF  <table-name>  AS $$

// My function logic here 
// which returns column1, column2, column3

$$ LANGUAGE sql STABLE; 
Opposition answered 15/1, 2020 at 6:25 Comment(5)
@a_horse_with_no_name hasura mentioned in their documentation "Return type: MUST be SETOF <table-name>" So we can't use ` setof <type-name> `Opposition
@a_horse_with_no_name I dont want to create extra tables/view as I have to write number of functions. And we can't use virtual table i.e. RETURNS SETOF Table(....)Opposition
@JimJones Hasuar already mentioned that "Return type: MUST be SETOF <table-name>" Refer : docs.hasura.io/1.0/graphql/manual/schema/custom-functions.html So we can't use itOpposition
how to overcome this issue?Teodoor
@Teodoor Create a new dummy table to match the return type, and use that.Inherence

© 2022 - 2024 — McMap. All rights reserved.