Re: Select rows when all all ids of its children records matches

Поиск
Список
Период
Сортировка
От Arup Rakshit
Тема Re: Select rows when all all ids of its children records matches
Дата
Msg-id 3A9D72A5-E030-4E56-B5DB-F0E9E15F5387@zeit.io
обсуждение исходный текст
Ответ на Re: Select rows when all all ids of its children records matches  (Rob Sargent <robjsargent@gmail.com>)
Список 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



On 12-Sep-2018, at 9:47 PM, Rob Sargent <robjsargent@gmail.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 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 по дате отправления:

Предыдущее
От: Rob Sargent
Дата:
Сообщение: Re: Select rows when all all ids of its children records matches
Следующее
От: Scot Kreienkamp
Дата:
Сообщение: RE: PG9.1 migration to PG9.6, dump/restore issues