0

WHERE & the operator vocabulary

SQLused in ~100% of apps

Your DevLog homepage is about to grow a search box. Type "postgres" and the feed should narrow to just the matching posts — and it must never, under any phrasing, show bob's private draft to a stranger. Both of those are WHERE clauses. One is a feature; the other, written carelessly, is the security bug that gets a company in the news.

Core idea. A WHERE clause is a boolean expression evaluated once per row, and only rows where it evaluates to true survive. Every operator you learn here — =, <>, <, >, BETWEEN, LIKE/ILIKE, IN — is just a different way of computing that one true/false answer. Combine tests with AND, OR and NOT, but know that AND binds tighter than OR: an unparenthesized mix of the two is the single most common way a query returns rows it should never have shown.
Playground, this isn't a screenshot
where like_count >= 30
titleownerpubliclikesverdictkept?
Why I switched to Postgresalicetrue42truekept
RLS notes (draft)alicefalse0falsedropped
Ships on Fridaysbobtrue17falsedropped
Secret roadmap (draft)bobfalse3falsedropped
Indexing tips for Postgresalicetrue88truekept
My Vim setupbobtrue5falsedropped
returns2 rows

The six comparison operators — =, <>, <, >, <=, >= — each yield true or false for every row. Two posts clear 30 likes.

The one rule under all of it: a WHERE clause keeps a row only when its expression is true. false drops the row, and so does NULL— "unknown" is not "true". Every operator on this page is just a different way of computing that one verdict.
↑ play a little first, then dig in