Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT where value in collection of ranges

I'm trying to select rows where a value is present in any of a collection of ranges. So far, I've only been able to make the following work:

SELECT * FROM table
WHERE num <@ numrange(1,4) OR num <@ numrange(7,11)

I was hoping I would be able to get something like

SELECT * FROM table
WHERE num <@ ANY(numrange(1,4), numrange(7,11))

working, but I haven't had any luck with it.

Any idea of a better solution than chaining ORs together?

like image 212
pgoggijr Avatar asked Oct 18 '22 10:10

pgoggijr


1 Answers

You were close... The value in the ANY(...) expression needs to be an array:

SELECT * FROM table
WHERE num <@ ANY(ARRAY[numrange(1,4), numrange(7,11)])
like image 51
Nick Barnes Avatar answered Oct 21 '22 03:10

Nick Barnes