I want to achieve such a subquery, how to do it #1868
-
|
Beta Was this translation helpful? Give feedback.
Answered by
laurenceisla
Jun 8, 2021
Replies: 1 comment 4 replies
-
Looks like embedding in PostgREST won't filter the left table, for more complicated joins it's recommended to create custom VIEWS according to the docs. After joining /multi_question_view?paperId=eq.1002&questionType=eq.1 Edit: CREATE FUNCTION get_multi_question(p_id int, q_type text) RETURNS TABLE (...) AS $$
SELECT ... FROM multi_question WHERE questionId in (
SELECT questionId
FROM paper_manage
WHERE paperId = p_id AND questionType = q_type
);
$$ LANGUAGE SQL STABLE; And your query would look like this: GET /rpc/get_multi_question?p_id=1002&q_type=1 |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
wolfgangwalther
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like embedding in PostgREST won't filter the left table, for more complicated joins it's recommended to create custom VIEWS according to the docs. After joining
multi_question
andpaper_manage
in the VIEWmulti_question_view
, for instance, your query would look like this./multi_question_view?paperId=eq.1002&questionType=eq.1
Edit:
Taking into consideration what Steve mentioned below, a VIEW may not be your best choice and using a function is a better alternative. Something like: