1

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?

0

1 Answer 1

6

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])
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.