WHERE & Filters
Four products sit as rows, one of them with a blank value. The test price > 40 keeps just two, but the test = NULL keeps zero, so even the blank row stays hidden.
- ▸A row survives only when its test comes out TRUE; one that comes out UNKNOWN is dropped, same as FALSE.
- ▸
category = NULLmatches no rows at all, not even the row whose value is truly blank. - ▸Without parentheses,
a OR b AND cbecomesa OR (b AND c):ANDgroups ahead ofOR.
The products table holds four rows: Keyboard, Mouse, Monitor, Cable. You want only the ones priced over 40, so you add a test after the table: SELECT name, price FROM products WHERE price > 40.
The engine takes that test, price > 40, and runs it against each row on its own. Keyboard at 42.00 passes (TRUE), Mouse at 17.50 fails (FALSE), Monitor at 299.00 passes, Cable at 4.50 fails. Two rows come out. The per-row test that decides keep-or-drop is the predicate, and a row reaches the result only when its predicate is TRUE, never on a FALSE.
The test runs at a fixed spot in the pipeline. FROM products gathers the table's rows first, then the predicate filters those rows, and only the survivors reach the select list. So the filter sees the raw stored rows, not the name, price shape you wrote: the select list is applied last, to whatever rows are left. PostgreSQL's plan, its record of how it ran the query, shows the same order: the test sits inside the Seq Scan, its pass over every row, and Rows Removed by Filter counts the rows the test dropped.