我正在尝试在 Hasura 中创建一个函数来查询用户附近的帖子。我得到了那个工作,但我也想订购这些帖子。我收到一个 Postgres 错误,内容为:
“postgres-error : 列“b.Volume”必须出现在 GROUP BY 子句中或用于聚合函数中”
我是 Hasura 和 Postgres 的新手,我不确定您是否被允许做这样的事情。这是我的代码:
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$
Run Code Online (Sandbox Code Playgroud)