非常沮丧地发现 Supabase 不允许使用 GraphQL 对相关表进行开箱即用的查询。我正在尝试创建一个函数来帮助完成此任务,但我陷入困境。当我运行这个 SQL 脚本时,它成功了,但是当我尝试在 GraphiQL 游乐场中点击它时,该函数不存在。
CREATE OR REPLACE FUNCTION filter_events_search(gender VARCHAR)
RETURNS TABLE(
id UUID
)
LANGUAGE plpgsql
AS $$
BEGIN
RETURN QUERY
SELECT
e.id
FROM
events e
JOIN teams t ON e.team_id = t.id
WHERE
t.gender = filter_events_search.gender;
END;
$$;
有什么建议吗?我也尝试过稳定与不可变。
弄清楚了,以防其他人陷入困境。
create or replace function filter_events_search(gender varchar, birth_year int, state varchar)
returns setof events
stable
language sql
as
$$
select
e.*
from
events e
join teams t on e.team_id = t.id
where
e.status = 'pending'
and
t.gender = filter_events_search.gender
and
t.birth_year = filter_events_search.birth_year
and
t.state = filter_events_search.state
order by
e.date;
$$;