From: | Arup Rakshit <ar(at)zeit(dot)io> |
---|---|
To: | Rob Sargent <robjsargent(at)gmail(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Select rows when all all ids of its children records matches |
Date: | 2018-09-12 16:19:18 |
Message-ID: | 3A9D72A5-E030-4E56-B5DB-F0E9E15F5387@zeit.io |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi Rob,
I figured it out. thanks. It is giving correct data.
> Aren't you looking for cte.tags = array[1,2]?
posts_tags_cte has tags column, so I am using it.
Thanks,
Arup Rakshit
ar(at)zeit(dot)io
> On 12-Sep-2018, at 9:47 PM, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:
>
>
>
> 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 <http://posts.id/> FROM posts_tags_cte JOIN posts ON posts.id <http://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]?
>
From | Date | Subject | |
---|---|---|---|
Next Message | Scot Kreienkamp | 2018-09-12 18:28:16 | RE: PG9.1 migration to PG9.6, dump/restore issues |
Previous Message | Rob Sargent | 2018-09-12 16:17:54 | Re: Select rows when all all ids of its children records matches |