OR Operator

OR Operator explained with practical SQL patterns, edge cases, and production-ready guidance.

4 min read · Last updated: March 2026 · Back to overview

Quick Answer

The OR operator returns TRUE if at least one of the two boolean expressions is TRUE. It returns FALSE only when both expressions are FALSE. OR is used in WHERE clauses to match rows that satisfy any one of multiple conditions.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

Introduction to the PostgreSQL OR operator

The OR operator is a logical operator that combines two boolean expressions. Like AND, it works with the three-valued boolean logic of PostgreSQL: TRUE, FALSE, and NULL.

Basic syntax:

expression1 OR expression2

The truth table for OR:

  • TRUE OR TRUETRUE
  • TRUE OR FALSETRUE
  • TRUE OR NULLTRUE (one side is definitively true)
  • FALSE OR FALSEFALSE
  • FALSE OR NULLNULL
  • NULL OR NULLNULL

The key rule: OR returns TRUE if at least one expression is true. It only returns FALSE when both are definitively false.

Basic OR examples

SELECT true  OR true   AS result;  -- t
SELECT true  OR false  AS result;  -- t
SELECT true  OR null   AS result;  -- t
SELECT false OR false  AS result;  -- f
SELECT false OR null   AS result;  -- null
SELECT null  OR null   AS result;  -- null

Using OR in a WHERE clause

In practice, OR lets you match rows that satisfy any of several conditions. This example finds films from the DVD rental database with a rental rate of $0.99 or $2.99:

SELECT title, rental_rate
FROM film
WHERE rental_rate = 0.99
   OR rental_rate = 2.99;

Partial result:

title                       | rental_rate
-----------------------------+-------------
Academy Dinosaur            |        0.99
Adaptation Holes            |        2.99
Affair Prejudice            |        2.99
African Egg                 |        2.99
...

OR vs. IN: choosing the right tool

When you are testing the same column against multiple values, IN is a cleaner alternative to chaining OR:

-- Equivalent queries:
WHERE rental_rate = 0.99 OR rental_rate = 2.99 OR rental_rate = 4.99

WHERE rental_rate IN (0.99, 2.99, 4.99)

IN is easier to read as the list grows and is treated identically by the planner for small value lists.

AND with OR: precedence and parentheses

AND has higher precedence than OR, so mixed expressions without parentheses may not behave as expected:

-- This is evaluated as: (rating = 'G' AND length > 100) OR rental_rate < 1
WHERE rating = 'G' AND length > 100 OR rental_rate < 1;

-- To require length > 100 for both cases, use parentheses:
WHERE (rating = 'G' OR rental_rate < 1) AND length > 100;

Always add parentheses when mixing AND and OR to make your intent unambiguous.

NULL behavior with OR

Because TRUE OR NULL is TRUE, filtering with OR can sometimes include more rows than expected when nulls are involved. When both sides are indeterminate — FALSE OR NULL — the result is NULL, and the row is excluded from the result set:

-- Rows where either status is unknown (NULL) or rating is 'G'
-- will be included only if rating = 'G' is TRUE
SELECT title, rating
FROM film
WHERE rating = 'G'
   OR some_nullable_column = 'value';

Reference: PostgreSQL documentation — Logical Operators.

Continue in Filtering Data: LIMIT.

Related in this section: PostgreSQL WHERE · AND Operator · LIMIT

Frequently Asked Questions

What does OR return when one expression is NULL?

TRUE OR NULL returns TRUE, because one side is definitively true. FALSE OR NULL returns NULL, because the outcome is uncertain — the NULL side could be either true or false. NULL OR NULL returns NULL.

When should I use OR vs. IN in a WHERE clause?

Use IN when you are comparing the same column against a list of values — it is more readable and scales better: WHERE status IN ('active', 'pending', 'trial'). Use OR when the conditions involve different columns or more complex expressions: WHERE amount > 1000 OR customer_tier = 'vip'.

Does OR have higher or lower precedence than AND in PostgreSQL?

OR has lower precedence than AND. This means WHERE a OR b AND c is evaluated as WHERE a OR (b AND c). Always use parentheses when combining both operators to avoid subtle logic errors: WHERE (a OR b) AND c vs WHERE a OR (b AND c) can return very different result sets.

Can multiple OR conditions hurt query performance?

Yes. A long chain of OR conditions on the same column can prevent PostgreSQL from using an index efficiently, resulting in a sequential scan. For equality checks on one column, replacing OR with IN is semantically equivalent and may be better optimized. For OR conditions across different columns, PostgreSQL can use a BitmapOr plan to combine separate indexes, but this is less efficient than a single index scan.

Is there a NOT OR operator in PostgreSQL?

There is no NOT OR keyword, but you can negate an OR expression by wrapping it: WHERE NOT (status = 'cancelled' OR status = 'refunded'). This is equivalent to WHERE status != 'cancelled' AND status != 'refunded' — which you can also write as WHERE status NOT IN ('cancelled', 'refunded').