1

I've got some table ignore with col ignored_entry_ids contains array of integer. For example:

id     ignored_entry_ids
1      {1,4,6}
2      {6,8,11}
3      {5,6,7}

How can I select numbers that exists in every row with array? (6 in examle)

2
  • What exactly is the result you want? What should be the result if you query for the number 5? Commented Aug 29, 2013 at 11:01
  • Result is array of enrty_id (from ignored_entry_ids column) that ignored by all users. In other words^ numbers that exists in all rows in ignored_entry_ids column. Commented Aug 29, 2013 at 11:20

1 Answer 1

3

If your numbers are unique inside array, you can do something like this, don't think it could be made without unnest

with cte as (
    select id, unnest(ignored_entry_ids) as arr
    from ign
)
select arr
from cte
group by arr
having count(*) = (select count(*) from ign)

sql fiddle demo

if numbers are not unique, add distinct:

with cte as (
    select distinct id, unnest(ignored_entry_ids) as arr
    from ign
)
select arr
from cte
group by arr
having count(*) = (select count(*) from ign)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.