Skip to content

I want to achieve such a subquery, how to do it #1868

Answered by laurenceisla
edcjian asked this question in Q&A
Discussion options

You must be logged in to vote

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 and paper_manage in the VIEW multi_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:

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…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@steve-chavez
Comment options

@laurenceisla
Comment options

@wolfgangwalther
Comment options

@laurenceisla
Comment options

Answer selected by wolfgangwalther
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants