Chapter 17: PostgreSQL Operators

PostgreSQL: Operators β˜•πŸ”§

When people say β€œPostgreSQL operators”, they usually mean all the special symbols and short keywords that you put between values to compare them, combine them, do math with them, check membership, work with JSON, do pattern matching, do bitwise operations, etc.

PostgreSQL has way more operators than most other databases β€” and many of them are very expressive and unique.

1. Quick classification – the families of operators you’ll meet every day

Category Most important operators Typical feeling / use case PostgreSQL strength level
Arithmetic + – * / % ^ |/ @ Money calculations, age computation β˜…β˜…β˜…β˜†β˜†
Comparison = <> != < > <= >= IS [NOT] NULL Filtering rows β˜…β˜…β˜…β˜…β˜…
Logical AND OR NOT Combining conditions β˜…β˜…β˜…β˜…β˜†
String / Pattern matching | LIKE ILIKE ~ ~* SIMILAR TO Search, validation β˜…β˜…β˜…β˜…β˜…
JSON/JSONB -> ->> #> #>> @> <@ ? ?& ?| @? @@ Modern app data, API responses β˜…β˜…β˜…β˜…β˜…β˜… (best in class)
Array && <@ @> = && | & Tags, permissions, multivalue columns β˜…β˜…β˜…β˜…β˜…
Fuzzy / Similarity % <-> <@> <% (with pg_trgm extension) Search-as-you-type, typo-tolerant search β˜…β˜…β˜…β˜…β˜†
Bitwise & | # ~ << >> Flags, permissions, low-level bit manipulation β˜…β˜…β˜…β˜†β˜†
Geometric / Geometric ops && <-> @> <@ << >> &< &> GIS, bounding boxes (with PostGIS even more) β˜…β˜…β˜…β˜…β˜†
Text search @@ @@@ <-> (with tsvector / tsquery) Full-text search β˜…β˜…β˜…β˜…β˜…
Containment / Overlap @> <@ && (used in many types: jsonb, array, range, gist indexes…) β€œcontains”, β€œoverlaps” checks β˜…β˜…β˜…β˜…β˜…

2. Most frequently used operators – with real examples (our bookstore_demo style)

Let’s assume we have the books and customers tables from our previous demo database.

Arithmetic & Math operators

SQL

Comparison & IS / IS NOT

SQL

Logical operators (AND / OR / NOT)

SQL

String concatenation & LIKE / ILIKE

SQL

Regular expressions (~ ~* !~ !~*)

SQL

JSONB operators – PostgreSQL’s superpower in 2026

SQL

Array operators (very useful for tags, roles, etc.)

SQL

Containment & Overlap (works on jsonb, arrays, ranges, geometry…)

SQL

Full-text search operators (basic example)

SQL

3. Quick reference table – top 30 operators beginners should know by heart

Operator Meaning Example Returns
= Equals price = 399 boolean
<> / != Not equals status <> ‘cancelled’ boolean
LIKE / ILIKE Pattern match (% _) title ILIKE ‘%harry%’ boolean
~ / ~* Regex match / case-insensitive email ~* ‘gmail.com$’ boolean
&& Array overlap / jsonb key overlap tags && ARRAY[‘sci-fi’] boolean
@> Contains details @> ‘{“in_stock”: true}’ boolean
<@ Is contained by ARRAY[‘a’,’b’] <@ tags boolean
-> Get JSON object field as jsonb data -> ‘address’ jsonb
->> Get JSON object field as text data ->> ‘city’ text
|| String / array concatenation name || ‘ ‘ || surname text / array
+ – * / Arithmetic price * 1.18 numeric
BETWEEN Inclusive range year BETWEEN 2000 AND 2010 boolean
IN Membership status IN (‘shipped’,’delivered’) boolean
IS NULL Null check phone IS NULL boolean
AND / OR Logical price < 500 AND stock > 0 boolean

Your mini homework right now

Try these in your bookstore_demo (or college_db):

  1. Find books cheaper than β‚Ή300 using <
  2. Find customers whose email contains β€œgmail” using ILIKE
  3. Use ->> if you added any JSONB column
  4. Use && if you add a tags array column

Next class?

Tell me:

  • Want deep dive into JSONB operators (most powerful in 2026)?
  • Full-text search operators & tsvector / tsquery?
  • Array operators with real use-cases?
  • Or custom operators / operator classes (advanced)?

Your guru is ready β€” what’s the next topic? πŸš€

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *