Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 'range' of integers (in this case destination ports) that occur:

For example: 33848-33254.

I want to select 'all' of these without having to do one at a time. is there a range operator? Or should I just use 'between'?

share|improve this question
between is just fine, nothing wrong with it. – a_horse_with_no_name Sep 26 '12 at 21:47

You can use BETWEEN or greater than/less than operators:

select *
from yourtable
where col1 >= 33254 and col1 <= 33848;


select *
from yourtable
where col1 between 33254 and 33848;

see SQL Fiddle with Demo

share|improve this answer
I've been told that it's better to use the lt/gt ops, because "performance". Is that a lie? – jcolebrand Sep 26 '12 at 21:34
@jcolebrand I am not sure, we probably need feedback from some of the other experts on the site. – bluefeet Sep 26 '12 at 21:46
@jcolebrand: yes that's a lie. between will work just as fast as using < and >. And that's true for almost all DBMS, not only Postgres – a_horse_with_no_name Sep 26 '12 at 21:46

BETWEEN is your friend, as in

SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.