PostgreSQL NOT BETWEEN operator is used to match all values against a range of values excluding the values in the mentioned range itself.
Syntax: value NOT BETWEEN low AND high; Or, Syntax: value < low OR value > high;
The NOT BETWEEN operator is used generally with WHERE clause with association with SELECT, INSERT, UPDATE or DELETE statement.
For the sake of this article we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link in our examples.
Here we will query for the payment whose amount is not between 3 USD and 5 USD, using the NOT BETWEEN operator in the “Payment” table of our sample database.
SELECT customer_id, payment_id, amount FROM payment WHERE amount NOT BETWEEN 3 AND 5;
Here we will query for getting the payment whose payment date is not between 2007-03-07 and 2007-03-29 using the BETWEEN operator in the “Payment” table of our sample database.
SELECT customer_id, payment_id, amount, payment_date FROM payment WHERE payment_date NOT BETWEEN '2007-03-07' AND '2007-03-29';
Note: While making date queries the literal date in ISO 8601 format i.e., YYYY-MM-DD should be used in PostgreSQL.
- PostgreSQL - NOT IN operator
- PostgreSQL - NOT LIKE operator
- PostgreSQL - BETWEEN operator
- PostgreSQL - IN operator
- PostgreSQL - ILIKE operator
- PostgreSQL - IS NULL operator
- PostgreSQL - LIKE operator
- PostgreSQL - UNION operator
- PostgreSQL - INTERSECT Operator
- PostgreSQL - EXCEPT Operator
- PostgreSQL - ANY Operator
- PostgreSQL - SOME Operator
- PostgreSQL - ALL Operator
- PostgreSQL - EXISTS Operator
- PostgreSQL - ORDER BY clause
- PostgreSQL - INNER JOIN
- PostgreSQL - Create Database
- PostgreSQL - COALESCE
- PostgreSQL - CASE Statement
- PostgreSQL - IF Statement
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.