pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Select rows when all all ids of its children records matches
Date: Wed, 12 Sep 2018 10:17:54 -0600
Message-ID: <b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com> (raw)
In-Reply-To: <F791B2E6-5D6D-44E0-B593-96E478B34A55@zeit.io>
References: <FF55BC81-BB56-45C3-BCA2-B7D0F8E81F4A@zeit.io>
	<fe916369-aa51-0e7b-3afa-eb89974dfcc4@gmail.com>
	<5E56CBFF-62E6-4C17-B6D8-BBC05BC10C8B@zeit.io>
	<CAKFQuwZN-Lk3ErCACMdQZYDiiCto0NkrgTKZNKshkgxN-iSd=A@mail.gmail.com>
	<EDC3D41A-E121-4245-BE30-AA017DDACA49@zeit.io>
	<F791B2E6-5D6D-44E0-B593-96E478B34A55@zeit.io>



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]?

view thread (9+ messages)  latest in thread

Message-ID: <b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com>
Permalink:  ../b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com/
Also on:    postgresql.org/message-id/b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: robjsargent@gmail.com
  Subject: Re: Select rows when all all ids of its children records matches
  In-Reply-To: <b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com>
  References: <FF55BC81-BB56-45C3-BCA2-B7D0F8E81F4A@zeit.io> <fe916369-aa51-0e7b-3afa-eb89974dfcc4@gmail.com> <5E56CBFF-62E6-4C17-B6D8-BBC05BC10C8B@zeit.io> <CAKFQuwZN-Lk3ErCACMdQZYDiiCto0NkrgTKZNKshkgxN-iSd=A@mail.gmail.com> <EDC3D41A-E121-4245-BE30-AA017DDACA49@zeit.io> <F791B2E6-5D6D-44E0-B593-96E478B34A55@zeit.io> <b384bb1a-4281-4745-6a5f-9b474d9b4560@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox