【发布时间】:2021-09-04 16:27:00
【问题描述】:
我正在尝试在 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$
【问题讨论】:
-
这能解决您的问题吗? stackoverflow.com/questions/19601948/…
标签: sql postgresql sql-order-by knn hasura