Re: Select rows when all all ids of its children records matches - Mailing list pgsql-general

From Rob Sargent
Subject Re: Select rows when all all ids of its children records matches
Date
Msg-id b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com
Whole thread Raw
In response to Re: Select rows when all all ids of its children records matches  (Arup Rakshit <ar@zeit.io>)
Responses Re: Select rows when all all ids of its children records matches  (Arup Rakshit <ar@zeit.io>)
List pgsql-general



On 09/12/2018 10:08 AM, Arup Rakshit wrote:
I tried :

WITH posts_tags_cte AS (
        SELECT post_id, array_agg(tag_id) as tags
        FROM posts_tags
        WHERE tag_id in (1, 2)
        GROUP BY post_id
)
SELECT posts.id FROM posts_tags_cte JOIN posts ON posts.id = posts_tags_cte.post_id
WHERE posts_tags_cte.tags @> array[1, 2]::int8[]

But it gives me all the posts.


Aren't you looking for cte.tags = array[1,2]?

pgsql-general by date:

Previous
From: Arup Rakshit
Date:
Subject: Re: Select rows when all all ids of its children records matches
Next
From: Arup Rakshit
Date:
Subject: Re: Select rows when all all ids of its children records matches