6

We can check if a specific value is contained in an array using 'X' = ANY(haystack). However, how do I check if an array of integers contains a value that is less than X?, e.g. I want to find all arrays that have at least one value lower than 100.

asked Dec 1, 2021 at 1:16
1
  • ANY works with arbitrary operators, not just = Commented Dec 1, 2021 at 23:04

1 Answer 1

9

Don't know if this is the answer, but one way of doing this is to create a range and then check if they overlap, e.g.

int4range(0, 100, '[]') @> ANY(t2.ages)

This works in cases when dealing with finite numbers, but would not work if ages can contain any negative value.

Update: Never mind, it was just 100 >= ANY(t2.ages).

answered Dec 1, 2021 at 1:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.