I'm trying to create a function in Hasura that queries the posts near a user. I got that working but I would also like to order the posts. I get a Postgres error that says:
"postgres-error : column "b.Volume" must appear in the GROUP BY clause or be used in an aggregate function"
I'm new to Hasura and Postgres and I'm not sure if you are allowed to do something like this or not. Here is my code:
CREATE OR REPLACE FUNCTION public.search_posts_near_user(id uuid, distance_kms integer, volume integer)
RETURNS SETOF user_posts
LANGUAGE sql
STABLE
AS $function$
SELECT A.id, A.location,
(SELECT json_agg(row_to_json(B)) FROM "Posts" B
WHERE (
ST_Distance(
ST_Transform(B.location::Geometry, 3857),
ST_Transform(A.location::Geometry, 3857)
) /1000) < distance_kms AND B."Volume" < volume
ORDER BY B."Volume" Desc
) AS nearby_Posts
FROM users A where A.id = id
$function$