1
votes

I have multiple fields in Postgresql table of the same type which is bigint. I would like to select values which are in the int range (-2147483647, 2147483647). I tried to do something like this but with multiple fields it does not really look good:

select * from test_table
where field1 between -2147483647 and 2147483647  
  and field2 between -2147483647 and 2147483647  
  and field3 between -2147483647 and 2147483647

How can I apply one range filtering for multiple columns?

1

1 Answers

6
votes

You can use an int8range combined with range operators and an array of the field values:

SELECT *
FROM test_table
WHERE int8range(-2147483647, 2147483647) @> ANY(ARRAY[field1, field2, field3])