This is the required query result from a function:
[{"id":1,"task":"Finish Task ONE"},{"id":2,"task":"Finish Task TWO"}]
And it is produced correctly in pgAdmin4 by: SELECT api.add_them(1,2) in 4.
However, when the function is invoked with Windows Curl or by an Android Studio app it produces:
[{"add_them":[{"id":1,"task":"Finish Task ONE"},{"id":2,"task":"Finish Task TWO"}]}]
So the function name is being included as a wrapper around the body.
The Windows curl script is:
curl http://localhost:3000/rpc/add_them -X POST ^
-H "Authorization: Bearer <My JWT Token>" ^
-H "Content-Type: application/json" ^
-H "Prefer: return=representation" ^
-d "{\"a\": 1, \"b\": 2}"
The Function is:
CREATE OR REPLACE FUNCTION api.add_them(
a integer,
b integer)
RETURNS setof json
LANGUAGE 'plpgsql'
COST 100
VOLATILE
ROWS 1000
AS $$
BEGIN
RETURN QUERY
SELECT array_to_json(array_agg(row_to_json(t)))
FROM ( select id, task from api.todos
where id >= a and id <= b) t;
END; $$;
ALTER FUNCTION api.add_them(a integer, b integer)
OWNER TO postgres;