PostgreSQL Between Operator is used to pick the values within a range. PostgreSQL Between Operator supports numbers and dates.
PostgreSQL Between Syntax:
SELECT column1, column2, ..... columnN FROM table_name WHERE test_expression [ NOT ] BETWEEN begin_expression AND end_expression;
1. BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression.
2. NOT BETWEEN returns TRUE if the value of test_expression is less than the value of begin_expression or greater than the value of end_expression.
PostgreSQL Between Examples:
Below table used for PostgreSQL Between Operator examples.
1. Find the employees who joined between 1980-01-01 and 1980-12-31.
select * from emp where hiredate between '1980-01-01' and '1980-12-31';
2. Find the rows who is getting salary between 1000 and 2000.
select * from emp where sal between 1000 and 2000;
PostgreSQL Not Between Operator:
3. Find the exmployees whose salary is not between 1000 and 2000.
select * from emp where sal not between 1000 and 2000;